bzoj2734 HNOI2012 Set Select a number of pressure DP __DP

Source: Internet
Author: User
Description

"Set theory and Graph theory" This course has a work problem, asking students to find {1, 2, 3, 4, 5} of all the following conditions to meet the subset: If X is in that subset, then 2x and 3x cannot be in the sub set. The students did not like the enumeration nature of the topic, so it became the following question: For any positive integer n≤100000, how to find {1, 2,..., n} to meet the constraints of the number of subsets (just output to 1,000,000,001 modulo results), Now you have the problem.

Input

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


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

Sample Input
4 Sample Output 8

"Sample Interpretation"

There are 8 sets that meet the requirements, namely the empty set, {1},{1,4},{2},{2,3},{3},{3,4},{4}. A: We write the relationship between x as a matrix. X 3x 9x ... 2x 6x 18x ... 4x 12x 24x ... Now the problem is to give you some matrix, ask not to select adjacent numbers, the number of solutions. Obviously the length of the matrix is log-level. So for each matrix, the direct-pressure DP finally rides the answers to all the matrices. Code:

#include <iostream> #include <cstdio> #include <cstring> #define P 1000000001 using namespace std;
int f[2][1<<12],n,vis[1<<12];
Long ans (1);
  int cal (int x) {int I,j,t,a,b,pre (0), ans (0);
  memset (F,0,sizeof (f));
  F[1][0]=1;
    For (i=0;x* (1<<i) <=n;i++) {memset (f+ (i&1), 0,sizeof (f) >>1);
    For (j=0,t=1;x*t* (1<<i) <=n;j++,t*=3); For (a=0;a< (1<<pre), a++) if (Vis[a]) for (b=0;b< (1&LT;&LT;J); b++) if (vis[b]&& (A&A
   MP;B) ==0) f[i&1][b]+=f[~i&1][a],f[i&1][b]%=p;
  Pre=j;
 }//cout<<f[0][0]<< ' <<f[0][1]<<endl;
 For (j=0;j< (1<<pre); j + +) ans+=f[~i&1][j],ans%=p;
return ans;
 int main () {scanf ("%d", &n); for (int i=0;i< (1<<12); i++) if (!) ( I<<1&i) &&! 
     (I>>1&i))
 Vis[i]=1; 
 for (int i=1;i<=n;i++) if (i%2&&i%3) ans*=cal (i), ans%=p;
cout<<ans<<endl;  }



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.