[SCOI2005] Non-aggression King

It is said that this is a one-way pressure DP. . . However, the konjac is not very sensitive. . . So this article is for sale now. . . QVQ

We just need to pre-store this question according to normal thinking. . .

Then enumerate it. . . There seems to be no mental stalk. . .

Just go to the code. . .

Silly code:

#include<iostream>
#include<cstdio>
using namespace std;

long long dp[11][110][350];
int f[110],sum[110];
int n,k,top;

inline bool check1(int x)
{
    if(x & x<<1) return 0;
    else return 1;
}

inline void init()
{
    int maxn=(1<<n)-1;
    for(int i=0;i<=maxn;i++)
        if(check1(i))
        {
            f[++top]=i;
            int t=i;
            while(t) sum[top]+=t%2,t>>=1;
        }
}

intmain ()
{
    scanf("%d%d",&n,&k);
    init();
    for(int i=1;i<=top;i++)
        if(sum[i]<=k)
            dp[1][i][sum[i]]=1;
    for(int i=2;i<=n;i++)
        for(int j1=1;j1<=top;j1++)
            for(int j2=1;j2<=top;j2++)
            {
                if(f[j1] & f[j2]) continue;
                if(f[j1] & f[j2]<<1) continue;
                if(f[j1]<<1 & f[j2]) continue;
                for(int j3=1;j3<=k;j3++)
                    if(sum[j1]+j3<=k)
                        dp[i][j1][sum[j1]+j3]+=dp[i-1][j2][j3];
            }
    long long ans=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=top;j++)
            ans+=dp[i][j][k];
    printf("%lld\n",ans);
}
code

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325049669&siteId=291194637