Title Link: http://www.lydsy.com/JudgeOnline/problem.php?id=1055
F[I][J][K] Indicates whether the interval i,j can be synthesized out of the character K, where k=1,2,3,4 represents the letter w,i,n,g, and then write a 64 times-times constant interval DP can be
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <
Algorithm> using namespace std;
const int m=205;
int n,w,i,n,g;
BOOL B[m][m][5],f[m][m][5];
Char C[m];
int get (char c) {if (c== ' W ') return 1;
else if (c== ' I ') return 2;
else if (c== ' N ') return 3;
else return 4;
} char nget (int x) {if (x==1) return ' W ';
else if (x==2) return ' I ';
else if (x==3) return ' N ';
else return ' G ';
} int main () {scanf ("%d%d%d%d", &w,&i,&n,&g);
Char s[3];
int x, y;
for (int i=1;i<=w;i++) {scanf ("%s", s+1);
X=get (S[1]);
Y=get (s[2]);
B[x][y][1]=true;
} for (int i=1;i<=i;i++) {scanf ("%s", s+1);
X=get (S[1]);
Y=get (s[2]);
B[x][y][2]=true;
} for (int i=1;i<=n;i++) {scanf ("%s", s+1);
X=get (S[1]);
Y=get (s[2]);
B[x][y][3]=true;
} for (int i=1;i<=g;i++) {scanf ("%s", s+1);
X=get (S[1]);
Y=get (s[2]);
B[x][y][4]=true;
} scanf ("%s", c+1);
int N=strlen (c+1); for (int i=1;i<=n;i++) F[i][i][get (c[i])]
= 1;
for (int l=2;l<=n;l++) for (int i=1;i+l-1<=n;i++) {int j=i+l-1; for (int k=i;k<=j;k++) for (int w=1;w<=4;w++) for (int p=1;p<=4;p++) for (int q=1;q<=4;q++) f[i][j][w]|=b [P] [Q]
[w]&f[i][k][p]&f[k+1][j][q];
} bool Flag=false;
for (int i=1;i<=4;i++) if (F[1][n][i]) {flag=true;printf ("%c", Nget (i));}
if (!flag) puts ("The name is wrong!");
}