Title Link: http://acm.fzu.edu.cn/problem.php?pid=2170
Stick a Baka the code souvenir.
There is a problem with the data, the input string length does not exceed 1000
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include < algorithm> #include <map> #include <queue> #include <stack> #include <cmath> #include < Vector> #define INF 0x3f3f3f3f#define inf 0x3fffffffffffffffll#define eps 1e-9#define pi acos ( -1.0) using namespace std ; typedef long long ll;const int maxn=1000+2;const int mod=1000000007;int Dp[maxn][maxn];char str[maxn<<1];int Main () {//freopen ("In.txt", "R", stdin); Freopen ("OUT.txt", "w", stdout); int t,n; scanf ("%d", &t); while (t--) {scanf ("%d", &n); Memset (Dp,0,sizeof (DP)); scanf ("%s", str+1); Dp[0][0]=1; int k; for (int i=0;i<=n;++i) for (int j=0;j<=n;++j) {if (!dp[i][j]) continue; k=i+j+1; if ((i&1) && (j&1)) {if (str[k]== ' B ') { Dp[i][j+1]+=dp[i][J]; DP[I+1][J]+=DP[I][J]; if (dp[i][j+1]>=mod) Dp[i][j+1]-=mod; if (dp[i+1][j]>=mod) Dp[i+1][j]-=mod; }} else if (i&1) {if (str[k]== ' W ') {DP[I][J+1]+=DP[I][J]; if (dp[i][j+1]>=mod) Dp[i][j+1]-=mod; } else {dp[i+1][j]+=dp[i][j]; if (dp[i+1][j]>=mod) Dp[i+1][j]-=mod; }} else if (j&1) {if (str[k]== ' W ') {DP[I+1][J]+=DP[I][J]; if (dp[i+1][j]>=mod) Dp[i+1][j]-=mod; } else {dp[i][j+1]+=dp[i][j]; if (dp[i][j+1]>=mod) Dp[i][j+1]-=mod; }} else {if (str[k]== ' W ') { DP[I][J+1]+=DP[I][J]; DP[I+1][J]+=DP[I][J]; if (dp[i][j+1]>=mod) Dp[i][j+1]-=mod; if (dp[i+1][j]>=mod) Dp[i+1][j]-=mod; }}} int ans=dp[n][n]; printf ("%d\n", ans); } return 0;}