标签:接受 技术分享 title php icp sans def opened linked
Sample Output
Source
1 #include<bits/stdc++.h> 2 #define mod 1000000007 3 using namespace std; 4 const int N=15,S=531441; 5 int ca,t,n,m,cur,mul,base[13],g[N][N][4]; 6 long long ans,f[2][S]; 7 char s[5]; 8 int change(char x){ 9 return x==‘C‘?0:(x==‘R‘?1:2); 10 } 11 void dfs(int c,int num,int up,int down,int right) 12 { 13 if (num>m) 14 { 15 if (c==1) f[cur][down]=(f[cur][down]+mul)%mod; 16 else f[cur][down]=(f[cur][down]+f[cur^1][up]*mul)%mod; 17 return; 18 } 19 if (g[c][num][0]==g[c][num][1]&&g[c][num][1]==g[c][num][2]&&g[c][num][2]==g[c][num][3]) 20 { 21 int add=g[c][num][0]; mul*=4; 22 if (right==-1||right==add) dfs(c,num+1,up*3+add,down*3+add,add); 23 mul/=4; return; 24 } 25 for (int i=0;i<4;++i) 26 { 27 int U=g[c][num][i]; 28 int R=g[c][num][(i+1)%4]; 29 int D=g[c][num][(i+2)%4]; 30 int L=g[c][num][(i+3)%4]; 31 if (right==-1||right==L) dfs(c,num+1,up*3+U,down*3+D,R); 32 } 33 } 34 int main() 35 { 36 scanf("%d",&t); base[0]=1; 37 for (int i=1;i<=12;++i) 38 base[i]=base[i-1]*3; 39 while (t--) 40 { 41 scanf("%d%d",&n,&m); 42 for (int i=1;i<=n;++i) 43 for (int j=1;j<=m;++j) 44 { 45 scanf("%s",s); 46 for (int k=0;k<4;++k) 47 g[i][j][k]=change(s[k]); 48 } 49 memset(f,0,sizeof(f)); 50 cur=ans=0; 51 for (int i=1;i<=n;++i) 52 { 53 cur^=1; mul=1; 54 dfs(i,1,0,0,-1); 55 for (int j=0;j<base[m];++j) 56 f[cur^1][j]=0; 57 } 58 for (int i=0;i<base[m];++i) 59 ans=(ans+f[cur][i])%mod; 60 printf("Case %d: %d\n",++ca,ans); 61 } 62 return 0; 63 }
标签:接受 技术分享 title php icp sans def opened linked
原文地址:http://www.cnblogs.com/zk1431043937/p/7750806.html