题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3195
看到数据范围就应该想到状压呢...
题解(原来是这样):https://www.cnblogs.com/LadyLex/p/7252789.html
代码如下:
#include<iostream> #include<cstdio> #include<cstring> using namespace std; typedef long long ll; int n,m,k; ll f[35][35][1<<9][10],z[10],mod=1000000007; int main() { scanf("%d%d%d",&n,&m,&k); z[0]=1; for(int i=1;i<=k+1;i++)z[i]=(z[i-1]<<1); f[2][0][0][0]=1; for(int i=2;i<=n;i++) for(int j=0;j<=m;j++) for(int s=0;s<z[k+1];s++) { for(int l=0;l<k;l++) { (f[i][j][s][l+1]+=f[i][j][s][l])%=mod; if(j<m&&i-(k-l)>0) (f[i][j+1][s^z[k]^z[l]][l]+=f[i][j][s][l])%=mod; } if((s&1)==0)f[i+1][j][s>>1][0]=f[i][j][s][k]; } printf("%lld",f[n+1][m][0][0]); return 0; }