[NOIP2006] Increase group Rokua P1066 2^k number

Source: Internet
Author: User

Title Description

Set R is a 2^k number and meets the following conditions:

(1) R is at least a 2-bit 2^k binary number.

(2) as the number of 2^k, except the last one, each of the R is strictly less than its right adjacent to the one.

(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 2^k, if s can be divided into at least 2 segments, then s corresponding to the binary number can be converted to the 2^k 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.

Input/output format

Input format:

Enter only 1 lines, two positive integers, separated by a space:

Kw

Output format:

The output is 1 lines, is a positive integer, for the calculated result, 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 and Output Sample input example # #:
3 7
Sample # # of output:
36
Description

NOIP 2006 Improvement Group Fourth question

Mathematical Statistics

It is obvious that the 2^k binary number can be converted into binary number analysis.

For example, 8-bit binary number 00000000, if you want to make up 2^3, you need to divide every 3 numbers into a paragraph: 00|000|000

0003-bit may have 2^3-1 species possible (1~7)

If each length is equal, since each segment may consist of the same number, and the actual number of elements is different, the total scheme number can be calculated with the combined number: C[2^k-1][n] (total N-segment)

If the length of the first paragraph is not equal to the back, it needs to be considered separately: c[2^k-(number I selected for first paragraph)][w/k] 1<=i<2^ (first segment bits) && 2^k-i>w/k← need to leave a position for the next number

1 /*by Silvern*/2#include <iostream>3#include <cstdio>4#include <cmath>5#include <cstring>6#include <algorithm>7 using namespacestd;8 intRead () {9     intx=0, f=1;CharCh=GetChar ();Ten      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} One      while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} A     returnx*F; - } - structnum{ the      Short intLen; -     inta[ $]; -}c[ -][ -]; - intn,k; + num C1,ans; - num Gadd (num a,num b) { +memset (c1.a,0,sizeofc1.a); Ac1.len=Max (A.len,b.len); at      for(intI=1; i<=c1.len;++i) { -c1.a[i]+=a.a[i]+B.a[i]; -c1.a[i+1]+=c1.a[i]/10000; -c1.a[i]%=10000; -     } -     if(c1.a[c1.len+1]) c1.len++; in     returnC1; - } to voidPrint () { +printf"%d", Ans.a[ans.len]); -      for(inti=ans.len-1;i>0;--i) {         theprintf"%d", ans.a[i]/ +); *printf"%d", ans.a[i]/ -%Ten); $printf"%d", ans.a[i]/Ten%Ten);Panax Notoginsengprintf"%d", ans.a[i]%Ten); -     } theprintf"\ n"); + } A intMain () { theK=read (); n=read (); +     inthk=1<< (n%k); -     inttk=1<<K; $     inti,j; $      for(i=0; i<=tk;++i) { -          for(j=0; j<=i;++j) { -             if(!j | |!i) {c[i][j].len=1; c[i][j].a[1]=1;} the             ElseC[i][j]=gadd (c[i-1][j],c[i-1][j-1]); -         }Wuyi     } theans.len=1; -      for(i=2; i<=n/k && i<tk;++i) Ans=gadd (ans,c[tk-1][i]); Wu      for(i=1; i1][n/K]); - Print (); About     return 0; $}

[NOIP2006] Increase group Rokua P1066 2^k number

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.