bzoj2734 "HNOI2012" collection selection

Source: Internet
Author: User

2734: [HNOI2012] Collection selection time limit: ten Sec Memory Limit: MB
Submit: 831 Solved: 487
[Submit] [Status] [Discuss] 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 Input
4Sample 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}.
HINT

Source

Day2




pressure DP idea good problem

Write such a matrix

1 3 9 27 ...

2 6 18 54 ...

4 12 36 108 ...

...

You can find a maximum of 12 rows.

So we just enumerate the upper left corner of the number x, we can get a different matrix, for each matrix need to select some number, but not the number of adjacent, the pressure DP solution.

For each matrix, multiplying the scheme number is the answer.




#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib > #include <algorithm> #define F (I,j,n) for (int. i=j;i<=n;i++) #define D (i,j,n) for (int i=j;i>=n;i--) # Define ll long long#define MAXN 100005#define mod 1000000001using namespace std;int n;ll Ans=1,f[20][4100],num[20];bool vs T[maxn];inline int read () {int X=0,f=1;char ch=getchar (); while (ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} inline ll Calc (int x) {int cnt=0;memset (num,0,sizeof (num)); memset (F,0,sizeof (f)); F[0][0]=1;while (x<=n) {Cnt++;int Tmp=x;while (tmp<=n) {num[cnt]++;vst[tmp]=true;tmp*=3;} F (i,0, (1<<num[cnt])-1) {int p;for (p=1;p<num[cnt];p + +) if ((i& (1<<)) && (P-1 (i&) <p)) break;if (p!=num[cnt]) continue; F (j,0, (1<<num[cnt-1])-1) if (! ( I&AMP;J)) (F[cnt][i]+=f[cnt-1][j])%=mod;} x*=2;} ll t=0; F (i,0, (1<<num[cnt])-1) (T+=f[cnt][i])%=mod;return T;} int main () {memset (vst,false,sizeof (VST)); N=read (); F (I,1,n) if (!vst[i]) (Ans*=calc (i))%=mod;printf ("%lld\n", ans); return 0;}


bzoj2734 "HNOI2012" collection selection

Related Article

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.