This paper mainly investigates the knowledge of combinatorial number, and the reference formula when initializing
first of all, a formula is the number of round numbers with Len length. Len, the first bit must be 1. then there's len-1 left behind. If the len-1 is an even number. so C (len-1, (len-1)/2+1) +c (len-1, (len-1)/2+2) + "" C (len-1,len-1)= (2^ (len-1)-C (len-1, (len-1)/2))/2;If Len is an odd numberthen it is (2^ (len-1))/2
1#include <cstdio>2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cmath>6#include <queue>7 using namespacestd;8 Const intmaxn= *;9 intm,t;Ten intC[MAXN][MAXN]; One intBIT[MAXN]; A voidInit ()//initialize number of combinations - { -c[0][0]=c[1][0]=c[1][1]=1; the for(intI=2; i<= -; i++) - { -c[i][0]=1; - for(intj=1; j<i;j++) +c[i][j]=c[i-1][j]+c[i-1][j-1]; -c[i][i]=1; + } A } at intCalcintN//sum of round numbers less than or equal to n - { - if(n<=1)return 0; - intlen=0; - while(n>0)//Find out the binary representation of the number - { in if(n&1) bit[len++]=1; - Elsebit[len++]=0; ton>>=1; + } - intans=0; the for(inti=len-1;i>0; i--)//finding the number of round with a length less than Len * { $ if(i%2==0) ans+= (1<< (I-1)))/2;Panax Notoginseng Elseans+= ((1<< (I-1))-c[i-1[-1)/2])/2; - } the intc1=0, c0=0; + for(intI=0; i<len;i++) A { the if(bit[i]==0) c0++; + Elsec1++; - } $ if(C0>=C1) ans++;//the number itself is the number of round $c1=1; c0=0; - for(inti=len-2; i>=0; i--)//Note that the count is zero- based - { the if(bit[i]==1)//this bit can become 0 - {Wuyi for(intj=i;j>=0&&j+c0+1>=i-j+c1;j--) Ans+=c[i][j];//J is the number of 0 that is ready to be added thec1++; - } Wu Elsec0++; - } About returnans; $ } - intMain () - { - inti,j,k; A init (); + intb; the //freopen ("1.in", "R", stdin); - while(SCANF ("%d%d", &a,&b)! =EOF) $ { theprintf"%d\n", Calc (b)-calc (A-1)); the } the return 0; the}
POJ 3252 Number of combinations