魔方阵

题目大意

太麻烦了……

打表做法

请先阅读OJ上本题的题解。
我们发现只需要维护可扩展源三角形,然后用最小表示法只有10种状态!
然后打表,flag[i,j]表示状态i变成状态j的方案数,dt1[i]和dt2[i]分别表示状态i下可选取的一级三角形和二级三角形个数,然后DP显然。

#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const ll mo=1000000007;
ll flag[10][10]={
 {1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },
 {1 ,1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },
 {1 ,0 ,1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },
 {1 ,2 ,0 ,1 ,0 ,0 ,0 ,0 ,0 ,0 },
 {1 ,2 ,0 ,0 ,1 ,0 ,0 ,0 ,0 ,0 },
 {1 ,1 ,1 ,0 ,0 ,1 ,0 ,0 ,0 ,0 },
 {1 ,0 ,2 ,0 ,0 ,0 ,1 ,0 ,0 ,0 },
 {1 ,3 ,0 ,2 ,1 ,0 ,0 ,1 ,0 ,0 },
 {1 ,2 ,1 ,1 ,0 ,2 ,0 ,0 ,1 ,0 },
 {1 ,4 ,0 ,4 ,2 ,0 ,0 ,4 ,0 ,1 }
},dt1[10]={12,9,6,6,6,3,0,3,0,0}
 ,dt2[10]={4 ,2,1,1,0,0,0,0,0,0};
ll c[30][30],f[250][250][20];
ll i,j,k,l,r,t,n,m,ans;
int main(){
 freopen("magic.in","r",stdin);freopen("magic.out","w",stdout);
 scanf("%lld%lld",&n,&m);
 f[0][0][0]=1;
 f[0][1][1]=4;f[0][1][2]=4;
 f[0][2][3]=4;f[0][2][4]=2;f[0][2][5]=8;f[0][2][6]=2;
 f[0][3][7]=4;f[0][3][8]=4;
 f[0][4][9]=1;
 c[0][0]=1;
 fo(i,1,14){
 c[i][0]=1;
 fo(j,1,i)
 c[i][j]=(c[i-1][j]+c[i-1][j-1])%mo;
 }
 fo(i,0,n-1)
 fo(j,0,m)
 fo(k,0,9)
 if (f[i][j][k])
 fo(l,0,9)
 if (flag[k][l])
 fo(t,0,dt2[l])
 if (j+t<=m)
 fo(r,0,dt1[l]-2*t)
 if (j+t+r<=m){
 f[i+1][j+t+r][l]+=f[i][j][k]*flag[k][l]*c[dt2[l]][t]*c[dt1[l]-2*t][r];
 f[i+1][j+t+r][l]%=mo;
 }
 fo(j,0,9) ans=(ans+f[n][m][j])%mo;
 fo(i,1,m) ans=ans*i%mo;
 printf("%lld\n",ans);
 fclose(stdin);fclose(stdout);
 return 0;
}

你可能感兴趣的:(魔方阵)