Noip2006 2^k Number Solving __DP

Source: Internet
Author: User

Topic Description Description
Set R is a 2k 2^k number, and the following conditions are true:
(1) R is at least a 2-bit 2k 2^k number.
(2) as a 2k number, except for the last one, every bit of R is strictly smaller than the one next to its right.
(3) when the R is converted to the 2 number Q, the total number of q is no more than W.
Here, the positive integers K (1≤k≤9 1≤k≤9) and W (k<w≤30000) W (k) are given in advance.
Q: How many different r are there to meet the above conditions?

Let's explain this from another angle: set S is a 01 string of length W (that is, the string s consists of W "0" or "1"), and s corresponds to Q in the above conditions (3). Dividing s from right to several segments of length k, each paragraph corresponding to a 2k number, if s can be divided into at least 2 segments, then the binary number of S can be converted to the above 2k 2^k number R.
Example: Set k=3,w=7. Then R is a octal number (23=8). Because of the w=7, the length of 7 of the 01 string by 3 bits, can be divided into 3 segments (that is, 1,3,3, the first paragraph on the left only one bits), the number of octal to meet the conditions are:
2 digits: High of 1:6 (ie 12,13,14,15,16,17), high to 2:5, ..., High to 6:1 (ie 67). A total of 6+5+...+1=21.
3 digits: The high level can only be 1, the 2nd digit is 2:5 (that is 123,124,125,126,127), the 2nd digit is 3:4, ... and the 2nd digit is 6:1 (i.e. 167). A total of 5+4+...+1=15.
So, there are 36 R to meet the requirements.

input Description Input Description
Only 1 rows, two positive integers, separated by a single space:
Kw

Output Description Description
A total of 1 lines, is a positive integer, for the calculated result, that is, the number of different r that satisfies the condition (expressed in decimal notation), requiring that the highest bit must not be 0, and that no other characters (such as spaces, newline characters, commas, etc.) should be inserted between numbers.
(Hint: A positive integer as a result can be large, but not more than 200 bits)

sample Input For example
3 7

Sample Output Sample
The solving

The subject seems to be abstract, but the "other angle" in the title description has revealed the characteristics of the topic. This 2k 2^k number can have a maximum of s= (w+k)/k s= (w+k)/k bit, and the highest value does not exceed m=2wmodk−1 m =2^{w\mod k}-1. (When w can divide K, although S is more than one bit, but at this point the highest value of the maximum m is 0, does not affect the correct answer)
This is the meaning of condition 1 and condition 3.

The condition is 2, and it essentially tells us about the recurrence relationship. There are two ways of thinking:

In the first case, F (i,j) F (i,j) represents the number of lengths I and the rightmost one does not exceed J J. Then there is f (i,j) =f (i,j−1) +f (i−1,j−1) F (i,j) =f (i,j-1) +f (i-1,j-1), that is, f (i,j) = f (i,j) = The number of schemes F (i,j−1) f (i,j-1), which is not J J, and the rightmost one is J J, F (i−1,j−1) f (i-1,j-1)
Answer ans=σs−1i=2f

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.