1157 2k binary number
2006 NOIP National League Improvement Group
time limit: 1 sspace limit: 128000 KBtitle level: Golden GoldTitle 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
Data range and Tips
Data Size & Hint
/* F[i][j] Indicates that there are several f[i][j]=f[i+1][j-1]+f[i+2][j-1]+...+f[maxx][j-1 with a length of J starting with I] but doing so will time out to observe: f[i+1][j]=f[i+2][j-1]+ ... +F[MAXX][J-1]F[I][J]=F[I+1][J-1]+F[I+1][J]* /
/*90-minute timeout code*/#include<iostream>#include<cstdio>#include<cstring>#defineLL unsigned long Long#defineMAXN 30010using namespacestd;intp,w,r,l,len=1;inta[maxn],f[ the];structnode{intl,a[ About]; }g[520][610],ans;voidAdd (Node &x,node &y) { intl1=x.l,l2=y.l,l3=1, I,j,k; LL c[ About]={0}; while(l3<=l1| | l3<=L2) {C[L3]+ = (x.a[l3]+Y.a[l3]); C[l3+1]+=c[l3]/1000000000; C[L3]%=1000000000; L3++; } while(l3>1&&c[l3]==0) l3--; X.L=L3; for(i=1; i<=l3;i++) X.a[i]=c[i];}voidprepare () {LL i,j,k; f[0]=1; for(LL i=1; i<=9; i++) F[i]=f[i-1]<<1; for(i=1; i<f[p];i++) { intq=f[p]-i-1; while(q>0) {g[i][2].l++; g[i][2].a[g[i][2].l]=q%1000000000; Q=q/1000000000; } } for(j=3; j<=l+1; j + +) for(i=1; i<f[p];i++) for(k=i+1; k<f[p];k++) Add (g[i][j],g[k][j-1]);}intMain () {LL i,j,k; scanf ("%d%d",&p,&W); R=w%p; L=w/p; Prepare (); for(i=1; i<=l;i++) A[i]=F[p]; A[l+1]=F[r]; for(j=2; j<=l+1; j + +) for(i=1; i<a[j];i++) Add (Ans,g[i][j]); printf ("%d", ANS.A[ANS.L]); for(i=ans.l-1; i>=1; i--) printf ("%09d", Ans.a[i]); cout<<Endl; return 0;}
/*AC Code */
#include <iostream>#include<cstdio>#include<cstring>#defineLL unsigned long Long#defineMAXN 30010using namespacestd;intp,w,r,l,len=1;inta[maxn],f[ the];structnode{intl,a[ About]; }g[520][610],ans;voidAdd (Node &x,node &y) { intl1=x.l,l2=y.l,l3=1, I,j,k; LL c[ About]={0}; while(l3<=l1| | l3<=L2) {C[L3]+ = (x.a[l3]+Y.a[l3]); C[l3+1]+=c[l3]/1000000000; C[L3]%=1000000000; L3++; } while(l3>1&&c[l3]==0) l3--; X.L=L3; for(i=1; i<=l3;i++) X.a[i]=c[i];}voidprepare () {LL i,j,k; f[0]=1; for(LL i=1; i<=9; i++) F[i]=f[i-1]<<1; for(i=1; i<f[p];i++) { intq=f[p]-i-1; while(q>0) {g[i][2].l++; g[i][2].a[g[i][2].l]=q%1000000000; Q=q/1000000000; } } for(j=3; j<=l+1; j + +) for(i=f[p]-1; i>=1; i--) {Add (G[i][j],g[i+1][j]); Add (G[i][j],g[i+1][j-1]); }}intMain () {LL i,j,k; scanf ("%d%d",&p,&W); R=w%p; L=w/p; Prepare (); for(i=1; i<=l;i++) A[i]=F[p]; A[l+1]=F[r]; for(j=2; j<=l+1; j + +) for(i=1; i<a[j];i++) Add (Ans,g[i][j]); printf ("%d", ANS.A[ANS.L]); for(i=ans.l-1; i>=1; i--) printf ("%09d", Ans.a[i]); cout<<Endl; return 0;}
Codevs 1157 2k binary number