1 条题解

  • 0
    @ 2023-10-18 9:56:19

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    const int N=12,M=1<<11;
    bool st[M];
    typedef long long LL;
    LL f[N][M];
    int n,m;
    bool check(int x)
    {
        int cnt=0;
        for(int i=0;i<m;i++)
        {
            if(x>>i&1)
            {
                if(cnt&1)
                {
                    return false;    
                }
                else
                {
                    cnt=0;
                }
            }
            else 
            {
                cnt++;
            }
        }
        if(cnt&1) return false;
        return true;
    }
    int main()
    {
        while(cin>>n>>m,n||m)
        {
            memset(st,0,sizeof st);
            memset(f,0,sizeof f);
            for(int i=0;i<(1<<m);i++)
            {
                if(check(i)) st[i]=true;
                else st[i]=false;
            }
            f[0][0]=1;
            for(int i=1;i<=n;i++)
            {
                for(int j=0;j<1<<m;j++)
                {
                    for(int k=0;k<1<<m;k++)
                    {
                        if((j&k)==0&&st[j|k])
                        {
                            f[i][j]+=f[i-1][k];
                        }
                    }
                }
            }
            cout<<f[n][0]<<endl;
        }
      
        return 0;
    }
    
    • 1

    信息

    ID
    760
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者