The number of problem solution set of election

The number of problem solution set of election

God construction problems,

For each quality factor excluding figures 2 and 3,

We construct a matrix (and possible dissatisfaction),

The first line of the first column is the number,

In the same line, the next column number is twice the number of this row,

In the same column, the number of the next line is three times the number of this line.

If we choose a number in the matrix,

The right number is twice this number can not be selected,

Similarly, the same number can not be selected from the following,

Can not be selected from the left, because it is the number of times,

Can not choose the number of the above, it is because this number three times,

in conclusion:

Chose a number can not be selected adjacent number,

Made, the number of columns <= \ (LOG_ 2} {(n-) <. 17 \) , the number of rows <= \ (LOG_. 3} {(n-) <. 11 \)

So, like pressure then:

Each of the different matrix independently of each other, according to the multiplication principle: the product of the number of each program is the answer to get.

Code:

#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const int N=4098,M=20,K=100006;
const ll mod=1e9+1;
int n,p,flag[N],book[K],num[M],f[M][N];
ll ans=1,sum;
inline int read(){
   int T=0,F=1; char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-') F=-1; ch=getchar();}
   while(ch>='0'&&ch<='9') T=(T<<3)+(T<<1)+(ch-48),ch=getchar();
   return F*T; 
}
void build(int x){
    p=1,sum=0; memset(f,0,sizeof(f)); memset(num,0,sizeof(num));
    for(int i=x;i<=n;i<<=1,++p) for(int j=i;j<=n;j*=3) ++num[p],book[j]=1;
    for(int i=0;i<(1<<num[1]);++i) f[1][i]=flag[i];
    for(int i=2;i<p;++i)
        for(int j=0;j<(1<<num[i-1]);++j)
            for(int k=0;k<(1<<num[i]);++k)
                if(flag[j]&&flag[k]&&!(j&k)) f[i][k]=(f[i][k]+f[i-1][j])%mod;
    for(int i=0;i<(1<<num[p-1]);++i) sum=(sum+f[p-1][i])%mod;
    ans=ans*sum%mod;
}
int main(){
    n=read();
    for(int i=0;i<=2048;++i) flag[i]=((i<<1)&i)?0:1;
    for(int i=1;i<=n;++i) if(!book[i]) build(i);
    printf("%lld\n",ans);
    return 0;
}

Guess you like

Origin www.cnblogs.com/ljk123-de-bo-ke/p/11323427.html