The
Problem Description
Set R is a 2k binary number and meets the following criteria:
(1) R is at least a 2-bit 2k binary number.
(2) as the 2k binary number, except the last one, each of the R is strictly smaller than the one adjacent to its right.
(3) when 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≤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 is composed of W "0" or "1"), and s corresponds to Q in the above condition (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). Since w=7, 01 strings of length 7 are divided into 3 segments (i.e., 1,3,3, the first segment on the left has only one bits), 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, ..., The high position 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), the 2nd bit is 3:4, ..., and the 2nd digit is 6:1 (that is, 167). A total of 5+4+...+1=15.
Therefore, there are 36 r that meet the requirements.
Input file
Input file digital.in only 1 lines, two positive integers, separated by a space:
K W
"output file"
Output file Digital.out is 1 lines, 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)
"Input Sample"
3 7
"Output sample"
$
Topic Analysis:
This question is the combination of mathematics in the m number of selected n questions, you can use the formula C[n,m]=c[n-1,m-1]+c[n-1,m] for what, we can analyze this, regardless of the first bit of the special case this problem is in each position to choose a number of each position, The maximum number is 2^k-1 and the minimum is 1. That is to say we have to choose the number of 2^k-1 number, as to the order of small to large, direct row order is not good, so no repetition of the number is the answer.
Now what if we add a special bit of the beginning? Take the example to see the first can get the largest number of 2^1-1, then choose this number of how many options. Can choose the number of numbers into 2^k-1-1, then we expand, we set all the number can put the number of positions represented as w/k, then the first bit of the remaining number is w%k, we enumerate this number, can constitute the number of scenarios is c[w/k,2^k-1-i], Summing up all the scenarios together is the final answer, but pay attention to the high precision, and the ordinary int type will be super memory limit, but since the high precision of each bit only with 0~9, then we can use char saved.
#include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <iostream > #include <iomanip> #include <cmath> #include <ctime> include<algorithm> using namespace std
;
int er[10]={1,2,4,8,16,32,64,128,256,512};
int ans[201];
Char f[514][514][200];
int len[514][514];
int main () {freopen ("digital.in", "R", stdin);
Freopen ("Digital.out", "w", stdout);
int n,m;
scanf ("%d%d", &n,&m);
int maxduan=m/n;
int max1=m%n;
Max1=er[max1]-1;
for (int i=1;i<=er[n]-1;i++) {f[0][i][1]=1;
Len[0][i]=1;
} f[1][1][1]=1;
Len[1][1]=1;
Len[0][0]=1; for (int i=1;i<=maxduan;i++) for (int j=1;j<=er[n]-1;j++) {if (i==1 && j==1) Conti
Nue
Len[i][j]=max (Len[i-1][j-1],len[i][j-1]);
for (int k=1;k<=len[i][j];k++) f[i][j][k]=f[i-1][j-1][k]+f[i][j-1][k];
for (int k=1;k<=len[i][j];k++) F[I][J][K]+=F[I-1][J-1][K]+F[I-1][J][K];
if (f[i][j][k]>=10) {F[I][J][K+1]+=F[I][J][K]/10;
f[i][j][k]=f[i][j][k]%10;
if (K==len[i][j]) len[i][j]++;
}} int lenans=0;
for (int i=2;i<=maxduan;i++) {Lenans=max (lenans,len[i][er[n]-1]);
for (int j=1;j<=lenans;j++) ANS[J]+=F[I][ER[N]-1][J];
for (int j=1;j<=lenans;j++) if (ans[j]>=10) {ANS[J+1]+=ANS[J]/10;
ans[j]=ans[j]%10;
if (J==lenans) lenans++;
}} for (int i=1;i<=max1;i++) {Lenans=max (lenans,len[maxduan][er[n]-1]);
for (int j=1;j<=lenans;j++) ANS[J]+=F[MAXDUAN][ER[N]-1-I][J];
for (int j=1;j<=lenans;j++) if (ans[j]>=10) {ANS[J+1]+=ANS[J]/10;
ans[j]=ans[j]%10; if (J==lenans) lenans++;
}}//cout<<ans;
for (int i=lenans;i>=1;i--) cout<<ans[i];
return 0;
}