显示代码纯文本
#include<cstdio>
const int mod=1000000007;
int K,M;
int f[330][330][5][5][5][5];
int main(){
freopen("mahjong.in","r",stdin);
freopen("mahjong.out","w",stdout);
scanf("%d%d",&K,&M);
f[0][0][0][0][4][4]=1;//(4,4):没有找出方案
for(int i=0;i<K;++i){
for(int j=0;j<=M;++j){
for(int r1=0;r1<=4;++r1){
for(int r2=r1;r2<=4;++r2){
if(r1==4&&r2==4)continue;
//f[i][j][r1][r2][4][4]
int x=f[i][j][r1][r2][4][4];
if(x==0)continue;
for(int k=r2;k<=4;++k){//第i种花色中使用的麻将数目
int res=k-r2;
if(res>=2){
if(res>=3){
(f[i+1][j+k][r2-r1][r2-r1+res-3][r2-r1][r2-r1+res-2]+=x)%=mod;
}
else {
(f[i+1][j+k][r2-r1][r2-r1+res][r2-r1][r2-r1+res-2]+=x)%=mod;
}
}
//碰?
if(res>=3){
(f[i+1][j+k][r2-r1][r2-r1+res-3][4][4]+=x)%=mod;
}
else{
(f[i+1][j+k][r2-r1][r2-r1+res][4][4]+=x)%=mod;
}
}
}
}
for(int r3=0;r3<=3;++r3){
for(int r4=r3;r4<=4;++r4){
int x=f[i][j][4][4][r3][r4];
if(x==0)continue;
for(int k=r4;k<=4;++k){
int res=k-r4;
if(res>=3){
(f[i+1][j+k][4][4][r4-r3][r4-r3+res-3]+=x)%=mod;
}
else{
(f[i+1][j+k][4][4][r4-r3][r4-r3+res]+=x)%=mod;
}
}
}
}
for(int r1=0;r1<4;++r1){
for(int r2=r1;r2<=4;++r2){
if(r1==4&&r2==4)continue;
for(int r3=0;r3<=4;++r3){
for(int r4=r3;r4<=4;++r4){
if(r3==4&&r4==4)continue;
//f[i][j][r1][r2][r3][r4]
int x=f[i][j][r1][r2][r3][r4];
if(x==0)continue;
for(int k=0;k<=4;++k){
if(k<r2){
if(k>=r4){
int res=k-r4;
if(res>=3){
(f[i+1][j+k][4][4][r4-r3][r4-r3+res-3]+=x)%=mod;
}
else{
(f[i+1][j+k][4][4][r4-r3][r4-r3+res]+=x)%=mod;
}
}
}else if(k<r4){
if(k>=r2){
}
}else{
int res=k-r2;
if(res>=2){
int res2=k-r4;
if(res2>=3)res2-=3;
//if(res>=3)res-=3;
int nxt3=r2-r1,nxt4=r2-r1+res-2;
int NXT3=r4-r3,NXT4=r4-r3+res2;
if(nxt3!=NXT3||nxt4!=NXT4){
if(res>=3)res-=3;
(f[i+1][j+k][r2-r1][r2-r1+res][r4-r3][r4-r3+res2]+=x)%=mod;
}
}else{
int res2=k-r4;
if(res2>=3){
(f[i+1][j+k][r2-r1][r2-r1+res][r4-r3][r4-r3+res2-3]+=x)%=mod;
}
else{
(f[i+1][j+k][r2-r1][r2-r1+res][r4-r3][r4-r3+res2]+=x)%=mod;
}
}
}
}
}
}
}
}
}
}
int ans=0;
for(int i=0;i<=4;++i){
for(int j=0;j<=4;++j){
ans=(ans+f[K][M][i][j][0][0])%mod;
}
}
printf("%d\n",ans);
return 0;
}
/*
5 0 2 0 0 0
to 3 5 4 4 0 0
*/
/*
0 1 4 3
0 4 1 3
3 1 1 3
1 2 2 3
//f[3][5][1][1][4][4]
0 2 2 4
//f[3][4][2][2][4][4]
0 3 3 2
3 0 3 2
3 3 0 2
1 1 4 2
1 4 1 2
4 1 1 2
2 2 2 2
//f[3][6][0][0][4][4]
*/