1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| const int N=170,P=1e9+7;
int n; int c[N]; char s[N]; int dp[N][N][2][2]; int F[N][N][2][2]; int S(int a,int b,int x1,int x2,int y1,int y2){ x1--,y1--; return (0ll+F[x2][y2][a][b]-F[x1][y2][a][b]-F[x2][y1][a][b]+F[x1][y1][a][b])%P; }
int main(){ n=rd(); int ans=0; rep(i,1,n) { scanf("%s",s+1); rep(j,1,n) c[j]=c[j-1]+(s[j]=='G'); memset(F,0,sizeof F); rep(i,1,n) rep(j,1,n) rep(a,0,1) rep(b,0,1) { F[i][j][a][b]=(0ll+F[i-1][j][a][b]+F[i][j-1][a][b]-F[i-1][j-1][a][b]+dp[i][j][a][b])%P; } memset(dp,0,sizeof dp); rep(l,1,n) rep(r,l,n) if(c[r]-c[l-1]==r-l+1) { (dp[l][r][0][0]+=S(0,0,l,r,l,r))%=P; (dp[l][r][1][0]+=S(0,0,1,l-1,l,r))%=P; (dp[l][r][0][1]+=S(0,0,l,r,r+1,n))%=P; (dp[l][r][1][1]+=S(0,0,1,l-1,r+1,n))%=P; (dp[l][r][0][1]+=S(0,1,l,r,r,n))%=P; (dp[l][r][1][1]+=S(0,1,1,l-1,r,n))%=P; (dp[l][r][1][0]+=S(1,0,1,l,l,r))%=P; (dp[l][r][1][1]+=S(1,0,1,l,r+1,n))%=P; (dp[l][r][1][1]+=S(1,1,1,l,r,n))%=P; } rep(l,1,n) rep(r,l,n) if(c[r]-c[l-1]==r-l+1) dp[l][r][0][0]++; rep(l,1,n) rep(r,l,n) rep(a,0,1) rep(b,0,1) if(dp[l][r][a][b]) ans=(ans+dp[l][r][a][b])%P; } Mod2(ans),printf("%d\n",ans); }
|