[Description]
Set R to a 2 ^ k Number and meet the following conditions:
(1) R must be at least two 2 ^ K hexadecimal numbers.
(2) As a 2 ^ K hexadecimal number, except for the last digit, each digit of R is strictly smaller than the adjacent one on the right.
(3) After converting R to a binary Q, the total number of digits of Q cannot exceed W.
Here, the positive integers K (1 ≤ k ≤ 9) and W (k <W ≤ 30000) are given in advance.
Q: How many R groups meet the preceding conditions?
Let's explain from another angle: Set s to a 01 string with a length of w (that is, string s consists of W "0" or "1 ), S corresponds to Q in the preceding condition (3. Divide s into several k-segment segments from the right. Each segment corresponds to a number of two K hexadecimal numbers. If s can be divided into at least two segments, then the binary number corresponding to s can be converted to the above 2 ^ K hexadecimal number R.
For example, set K to 3, w to 7. R is an octal number (2 ^ 3 = 8 ). Because W = 7, the 01 string with a length of 7 is divided into three segments (I .e., 1, 3, and the first segment on the left has only one binary segment ), the Octal numbers that meet the conditions are:
2 digits: (I .e ,..., The maximum value is 6:1 (67 ). 6 + 5 +... + 1 = 21.
3-digit: The value can only be 1 at a high position. The value of 2nd is (that is, 123,124,125,126,127), and the value of 2nd is ,..., 2nd bits are 6:1 (167 ). 5 + 4 +... + 1 = 15.
Therefore, there are 36 R instances meeting the requirements.
[Input format]
The input file contains only one line, which is two positive integers separated by a space:
K W
[Output format]
The output file contains one row and is a positive integer. It is the calculated result, that is, the number of different r values that meet the conditions (expressed in decimal number). The maximum bit must not be 0, no other characters (such as spaces, line breaks, and commas) must be inserted between numbers ).
(Note: the positive integer that serves as the result may be large, but cannot exceed 200 digits)
[Example input]
3 7
[Sample output]
36
[Analysis]
The best number theory and high precision.
ReferenceBear cave of dumb bear.
The analysis in the question from another perspective already contains the basic idea of this question. Take the example of the question as an example. For a 7-digit 01 string, divide it into three digits: 0 000. In addition to the first segment, each segment is less than (111) 2, that is, less than 2 K, and the first segment is naturally less than 2 w % K (also valid when w % K is 0).
If the first segment is 0, then when the number of 2 k hexadecimal digits is 2, 3 ,..., [N/K], if B _max is used to represent 2 K, the numbers of corresponding solutions are C [B _max-1] [2], C [B _max-1] [3],... c [B _max-1] [N/K] (C [I] [J] indicates selecting J from the number of I to form a group ).
If the first segment is not 0 and the first segment is set to X, the solution has c [B _max-x-1] [N/K.
In this way, the number of solutions is settled, and the rest is high. This formula can be used to calculate the number of combinations: C [N] [m] = C [n-1] [M-1] + C [n-1] [M]. In this way, only addition is used for high precision.
Original article Portal:Http://blog.sina.com.cn/s/blog_4c396f4301000bp6.html
# Include <stdio. h >#include <iostream> # define base 10000 using namespace STD; int B _max, h_max, N, K; int C [600] [600] [60], ans [60]; void plus1 (int A [], int B [], int C []) {A [0] = max (B [0], c [0]); For (INT I = 1; I <= A [0]; ++ I) {A [I] + = B [I] + C [I]; A [I + 1] + = A [I]/base; A [I] % = base;} while (A [A [0] + 1]) + + A [0];} void plus2 (int A [], int B []) {A [0] = max (A [0], B [0]); For (INT I = 1; I <= A [0]; ++ I) {A [I] + = B [I]; A [I + 1] + = A [I]/base; A [I] % = base ;} while (A [A [0] + 1]) + + A [0];} int main () {scanf ("% d", & K, & N); B _max = 1 <K; h_max = 1 <(N % K ); c [0] [0] [0] = C [0] [0] [1] = 1; for (INT I = 1; I <B _max; ++ I) for (Int J = 0; j <= I; ++ J) if (I = J) c [I] [J] [0] = C [I] [J] [1] = 1; else plus1 (C [I] [J], c [I-1] [J], C [I-1] [J-1]); For (INT I = 2; I <B _max & I <= N/K; ++ I) plus2 (ANS, C [B _max-1] [I]); For (INT I = 1; I