[codevs1157]2k Number of binary
Question 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≤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). Due to w=7, the length of 7 of 01 strings in 3 bits, can be divided 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, ..., 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), 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.
Input
Only 1 lines, two positive integers, separated by a space: K W
Output
is a positive integer, for the result of the calculation, that is, the number of different r that satisfies the condition (in decimal notation), the highest bit must not be 0, and the numbers must not be inserted into other 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 example
3 7
Output example
36
Data size and conventions
See " Question Description " and " output "
Exercises
W/k upward Rounding is the number of bits in the 2k number (so that the number of bits is N), and then we are equivalent to fill 2, 3, 4 、...、 n 2k of the number, and make the number decrement, the number of solutions, this DP a bit better.
Hint: Set F[I][J] Indicates the number of the number of the first I and the number of No. I is not less than J scheme. The problem is to open the scrolling array.
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype > #include <algorithm>using namespace Std;int read () {int x = 0, f = 1; char c = GetChar (); while (!isdigit (c)) {if ( c = = '-') f =-1; c = GetChar (); }while (IsDigit (c)) {x = x * + C-' 0 '; c = GetChar ();} return x * f;} struct LL {int len, a[210]; LL () {}LL operator = (const int& t) {if (!t) {a[1] = 0; len = 1; return *this;} len = 0; int T = t;while (t) a[++len] = t%, T/= 10;return *this;} LL operator + (const int& t) const {LL ans; ans = *this;ans. A[1] + = t;for (int i = 2; I <= Ans.len; i++) ans. A[i] + = ans. A[I-1]/ten, ans. A[i-1]%= 10;while (ans. A[ans.len] > 9) ans. A[ans.len+1] = ans. A[ans.len]/ten, ans. A[ans.len]%=, ans.len++;return ans;} LL operator + (const ll& t) const {LL ans; ans = *this;ans.len = max (Ans.len, T.len); for (int i = 1; I <= ans.len; i + +) ans. A[i] + = t.a[i];for (int i = 2; I <= Ans.len; i++) ans. A[i] + = ans. A[I-1]/10, Ans. A[i-1]%= 10;while (ans. A[ans.len] > 9) ans. A[ans.len+1] = ans. A[ans.len]/ten, ans. A[ans.len]%=, ans.len++;return ans;} LL operator + = (const ll& t) {*this = *this + T;return *this;} void print () {for (int i = len; i; i--) Putchar (a[i] + ' 0 '); return;}} ; #define MAXN 520LL F[2][MAXN], Ans;int main () {int w = read (), k = read (), int n = k% w? k/w + 1:k/w, mod = k% W, m = (1 << w)-1;if (n < 2) return puts ("0"), 0;bool cur = 0;for (int i = m; I >= 0; i--) f[0][i] = f[0][i+1] + 1;for (int i = 2; I <= n; i++) {cur ^= 1;f[cur][1<<mod] = f[cur][m+1] = 0;for (int j = (i = = n && MoD)? ( 1 << MoD)-1:m; J >= 0; j--) F[cur][j] = f[cur][j+1] + F[cur^1][j+1];ans + + f[cur][1];} Ans.print (); Putchar (' \ n '); return 0;}
This problem also needs to use the high precision ... Although there are only two big points.
[Codevs1157]2^k Number of binary