二进制数0和1的相同数量 [英] Binary numbers with the same quantity of 0s and 1s

查看:185
本文介绍了二进制数0和1的相同数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我解决欧拉项目的问题#15 我意识到,它可以解决与途径从开始的方式来结束组合#。总是产生的途径有向右或向下的选择相同的大小(或0和1)和正确的路线总是有0和1的相同数量。 因此,与0和1的相同数量的数字的二进制字数量是 C(2,1)的1位长度 C(4,2)的2位 C(6,3)的4位 ......

When I was solving Euler project problem #15 I realized that it can be solved with the # of combinations of ways of the route from start to end. The route generated always has the same size of right or down choices (or 0s and 1s) and the right routes always have the same qty of 0s and 1s. So qty of numbers with the same qty of 0s and 1s in a binary word are C(2,1) for 1bit length C(4,2) for 2bit " " C(6,3) for 4bit " " ...

现在谈到我的问题: 是否有一个功能,如果解决了一批具有0和1的相同数量? 我想,这将是更像是一个合乎逻辑的功能,我不想重复所有的数字,或者使用正则表达式(那会比迭代更糟)。

Now comes my questions: Is there a function that solves if a number has the same qty of 0s and 1s? I guess that it would be more like a logical function, I don't want to iterate all the digits or use regex (that would be worse than iterate).

**其他问题是这个平衡的价值观之间的增长和空间?

**Other question is about the growth and the space between this "balanced" values?

推荐答案

作为后续行动,以保罗的r的答案,有公式为中央二项式系数的简化,看到的 http://mathworld.wolfram.com/CentralBinomialCoefficient.html

As a follow up to Paul R's answer, there is a simplification of the formula for the central binomial coefficient, see http://mathworld.wolfram.com/CentralBinomialCoefficient.html

P = N! /((π/ 2)!)2 = 2 π/ 2 第(n-1)! /(N / 2)!

p = n! / ((n/2)!)² = 2n/2 (n-1)!! / (n/2)!

K!是双因子,计算时,这意味着你跳过所有其他号码:K! = K *(K-2)*(K-4)* ...(只要因子为正)。

k!! is the "double factorial", which means you skip every other number when calculating: k!! = k * (k-2) * (k-4) * ... (as long as the factor is positive).

有关你的计算大量数字将抵消(你可以同时计算分子和分母时,使用GCD本)

For your calculation a lot of numbers will cancel out (you can use the gcd for this when calculating numerator and denominator simultaneously)

这篇关于二进制数0和1的相同数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆