BZOJ2734[HNOI2012] Collection of selected

Source: Internet
Author: User

Description

"Set theory and Graph theory" This course has a homework problem, ask the students to find {1, 2, 3, 4, 5} All meet the following conditions of the subset: If X is in this subset, 2x and 3x cannot be in the sub-set. The students do not like the problem with the enumeration nature, so it becomes the following question: For any positive integer n≤100000, how to find out {1, 2,..., n} The number of the subset of the constraints to meet the above constraint (just output the results of 1,000,000,001 modulo), Now this problem is yours.

Input

Only one row, where there is a positive integer n,30% the data satisfies n≤20.

Output

Contains only a positive integer representing the number of subsets of {1, 2,..., n} that meet the above constraints.

Sample Input4Sample Output8
"Sample Interpretation"
There are 8 sets that meet the requirements, namely the empty set, {1},{1,4},{2},{2,3},{3},{3,4},{4}. The following:set X to a number that does not contain 2 and 3 factors, you can construct a matrix like this:
X X*3 X*3^2 X*3^3 . . .
2*x 2*x*3 2*x*3^2 2*x*3^3 . . .
2^2*x 2^2*x*3 2^2*x*3^2 2^2*x*3^3 . . .
2^3*x 2^3*x*3 2^3*x*3^2 2^3*x*3^3 . . .
. . . . . . .
. . . . . . .
. . . . . . .
  For example, when X=1:
1 3 9 27 . . .
2 6 18 54 . . .
4 12 36 108 . . .
8 24 72 216 . . .
. . . . . . .
. . . . . . .
. . . . . . .
in this way, the number pairs that cannot be taken at the same time must be around or up or down in the matrix. Because of the n<=1000000, the matrix has a maximum of 11 columns, and each row can be state-compressed DP. each number must and only exist in a matrix, there is no correlation between the two matrices, so the DP out of each matrix of the number of feasible scheme, the last multiplication is possible. Code:
1 Const2mo=1000000001;3 var4 I,j,k,l,n,m:longint;5A:Array[0.. -,0.. -] ofLongint;6B:Array[0.. -] ofLongint;7F:Array[0.. -,0..2048] ofLongint;8BoArray[0..100005] ofLongint;9BinArray[0.. -] ofLongint;Ten Ans:int64; One functionQQ (X:longint): Longint; A varI,j,y:longint; - begin -Fillchar (b,sizeof (b),0); thea[1,1]:=x; -    fori:=2  to  -  Do -   ifa[i-1,1]*2<=n ThenA[i,1]:=a[i-1,1]*2 ElseA[i,1]:=n+1; -    fori:=1  to  -  Do +    forj:=2  to  One  Do -   ifa[i,j-1]*3<=n Thena[i,j]:=a[i,j-1]*3 Elsea[i,j]:=n+1; +    fori:=1  to  -  Do A    forj:=1  to  One  Do at   ifA[i,j]<=n Then -   begin -b[i]:=b[i]+bin[j-1]; -bo[a[i,j]]:=1; -   End; -    fori:=0  to  -  Do in    forj:=0  toB[i] Dof[i,j]:=0; -f[0,0]:=1; to    fori:=0  to  -  Do +    forj:=0  toB[i] Do -   ifF[i,j]>0  Then the    fory:=0  tob[i+1] Do *   if(j andy=0) and(Y and(Y shr1)=0) Thenf[i+1, y]:= (f[i+1, Y]+f[i,j])MoDmo; $Exit (f[ -,0]);Panax Notoginseng End; - begin thebin[0]:=1; +    fori:=1  to  -  Dobin[i]:=bin[i-1]shl1; AREADLN (n); ans:=1; the    fori:=1  toN Do +   ifbo[i]=0  Thenans:= (ANS*QQ (i))MoDmo; - writeln (ans); $ End.
View Code

BZOJ2734[HNOI2012] Collection of selected

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.