"Pressure DP" bzoj2734-[hnoi2012) set of selection

Source: Internet
Author: User

Already August the pill, start liver work and prepare the college entrance examination!!

"The main topic"

"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. Now ask the following question: For any positive integer n≤100000, how to find the number of subsets of {1, 2,..., n} that meet the above constraints (just output the result of 1,000,000,001 modulo) (including the empty set).

Ideas

For an integer x of any and 6 coprime within N, we list A matrix:

X 3x 9x 27x ...

2x 6x 18x 54x ...

4x 12x 36x 108x ...

So we now enumerate this number x with 6 coprime and then proceed to the transition of State compression. This is somewhat similar to the previous king. F[I][J] represents the total possibility of line I, and the status of Line I is J. However, it is not necessarily a rectangle, the number of columns per row may be different, and for a number of rows J, we only need to enumerate 0. The status of the 2^j-1 and is recorded as before transferred to the next line of DP.

Here's a scrolling array, but don't forget to empty each new scrolling array.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 #defineMoD 10000000016 using namespacestd;7typedefLong LongLL;8 Const intmaxn= A;9 intN;Ten intusable[1<<maxn],f[2][1<<MAXN]; One BOOLmark[1<<MAXN]; A  - intUsable (intx) - { the     if(x<<1&x | | X>>1&AMP;X)return 0;Else return 1; - } -  - intdpintNow ) + { -Memset (F,0,sizeof(f)); +     intCur=0, before=-1;//before refers to the previous line with several numbers A      for(intI=0; now* (1<<i) <=n;i++)//enumerate the first number of each row to find the total number of rows at     { -Cur=1-cur; -         inttmp=now* (1<<i), J; -          for(j=0; tmp<=n;j++,tmp*=3);//find out how many numbers each line has -          for(intk=0;k< (1&LT;&LT;J); k++)//enumerates the status of the current row -         { inf[cur][k]=0;//"Don't forget to initialize ☆" -             if(Usable[k]) to             { +                 if(before==-1) {f[cur][k]=1;Continue;}//If this is the first row, set the feasible status to 1 -                  for(intp=0;p < (1<<before);p + +) the                     if(Usable[p]) *                         if((k&p) = =0) f[cur][k]=f[cur][k]+f[1-cur][p],f[cur][k]%=mod;//don't forget about the mod here. $             }Panax Notoginseng         } -Before=J; the     } +     intans=0; A      for(intI=0;i< (1<<before); i++) ans+=f[cur][i],ans%=MoD; the     return(ans); + } -  $ voidgetusable () $ { -memset (Usable,0,sizeof(usable)); -      for(intI=0;i< (2&LT;&LT;MAXN); i++) the         if(Usable (i)) usable[i]=1; - }Wuyi  the voidSolve () - { Wumemset (Mark,0,sizeof(Mark)); -LL ans=1;//in order to prevent the multiplication of overflow, you can first use Longlong, and then converted back to int About      for(intI=1; i<=n;i++) $         if((i%2) && (i%3)) ans= (ANS*DP (i))%MoD; -printf"%d\n",(int) ans); - } -  A intMain () + { thescanf"%d",&n); - getusable (); $ solve (); the     return 0; the}

"Pressure DP" bzoj2734-[hnoi2012) set of selection

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.