Title Description
Description
Set R is a 2k binary number and meets the following conditions:
(1) R is at least a 2-bit 2k binary number.
(2) as a 2k binary number, except the last one, each of the R is strictly less than its right adjacent to the next bit.
(3) After the R is converted to 2 Q, the total number of digits of Q does not exceed W.
Here, the positive integers K (1≤k≤9) and W (k<w< span>≤30000) are given beforehand.
Q: How many different r are there to meet the above conditions?
Let us explain from another angle that s is a 01 string with a length of W (that is, the string s consists of W "0" or "1") and s corresponds to Q in the above conditions (3). The S is divided from right to several segments of length k, each corresponding to a number of 2k, if s can be divided into at least 2 segments, then s corresponding to the binary number can be converted to the above 2k binary number R.
Example: Set k=3,w=7. Then R is an octal number (23=8). Because of w=7, 01 strings of length 7 are divided by 3 bits and can be broken into 3 segments (i.e. 1,3,3, the first paragraph on the left has only one bits), then the octal number that satisfies the condition is:
2 digits: High is 1:6 (i.e. 12,13,14,15,16,17), High is 2:5, ..., High is 6:1 (i.e. 67). A total of 6+5+...+1=21.
3 digits: The high can only be 1, the 2nd bit is 2:5 (that is, 123,124,125,126,127), 2nd is 3:4, ..., 2nd is 6:1 (that is, 167). A total of 5+4+...+1=15.
So there are 36 r that meet the requirements.
Enter a description
Input Description
Only 1 lines, two positive integers, separated by a space:
Kw
Output description
Output Description
A total of 1 rows, is a positive integer, for the result of the calculation, that satisfies the condition of the number of different R (in decimal number), the highest bit must not be 0, the numbers must not be inserted in addition to the number of characters (such as spaces, line breaks, commas, etc.).
(Hint: A positive integer as a result may be large, but not more than 200 bits)
Sample input
Sample Input
3 7
Sample output
Sample Output
36
/*Yang Hui Triangle strong burst space, only with char type*/#include<cstdio>#include<iostream>#include<cstring>#defineM 600using namespacestd;intk,w;structnode{Charch[201];intLen; Node () {memset (ch,0,sizeof(CH)); }};node Ans,c[m][m];node Jia (node X,node y) {node de; De.len=Max (X.len,y.len); for(intI=1; i<=de.len;i++) {De.ch[i]+=x.ch[i]+Y.ch[i]; De.ch[i+1]+=de.ch[i]/Ten; De.ch[i]%=Ten; } if(de.ch[de.len+1]!=0) de.len++; returnde;}intPOWW (intAintb) { int Base=a,r=1; while(b) {if(b&1) r*=Base; Base*=Base; b/=2; } returnR;}voidinit () {intT=POWW (2, K); for(intI=0; i<=t;i++) for(intj=0; j<=i;j++) if(j==i| | j==0) {c[i][j].ch[1]=1; C[i][j].len=1; } ElseC[i][j]=jia (c[i-1][j],c[i-1][j-1]);}intMain () {scanf ("%d%d",&k,&W); Init (); intn=w/k,yu=0; if(n<2) {printf ("0");return 0;} if(w%k!=0) { inttemp=w-k*n;n++; for(intI=0; i<temp;i++) Yu+=POWW (2, i); } for(intI=2; i<=n;i++) if(i!=n) Ans=jia (ANS,C[POWW (2, K)-1][i]); Else if(!yu) Ans=jia (ANS,C[POWW (2, K)-1][n]); Else if(Yu) { for(intj=1; j<=yu;j++) ans=jia (ANS,C[POWW (2, K)-1-j][n-1]); } for(inti=ans.len;i>=1; i--) printf ("%d", Ans.ch[i]); return 0;}
View Code
2k binary number (Codevs 1157)