标签:
区间DP……
dp[i][j][k]表示i~j段能不能变成k字符
输入写丑了,不要在意QAQ
1 #include<algorithm> 2 #include<iostream> 3 #include<cstdlib> 4 #include<cstring> 5 #include<cstdio> 6 #include<string> 7 #include<cmath> 8 #include<ctime> 9 #include<queue> 10 #include<stack> 11 #include<map> 12 #include<set> 13 #define rre(i,r,l) for(int i=(r);i>=(l);i--) 14 #define re(i,l,r) for(int i=(l);i<=(r);i++) 15 #define Clear(a,b) memset(a,b,sizeof(a)) 16 #define inout(x) printf("%d",(x)) 17 #define douin(x) scanf("%lf",&x) 18 #define strin(x) scanf("%s",(x)) 19 #define LLin(x) scanf("%lld",&x) 20 #define op operator 21 #define CSC main 22 typedef unsigned long long ULL; 23 typedef const int cint; 24 typedef long long LL; 25 using namespace std; 26 void inin(int &ret) 27 { 28 ret=0;int f=0;char ch=getchar(); 29 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=1;ch=getchar();} 30 while(ch>=‘0‘&&ch<=‘9‘)ret*=10,ret+=ch-‘0‘,ch=getchar(); 31 ret=f?-ret:ret; 32 } 33 int a[26][26][26],W,I,N,G; 34 int aa[222][222][26]; 35 const char qi[5]={‘\0‘,‘W‘,‘I‘,‘N‘,‘G‘}; 36 char s[111],ch[5]; 37 bool dfs(int l,int r,char c) 38 { 39 int &ret=aa[l][r][c-‘A‘]; 40 if(ret!=-1)return ret; 41 if(l==r&&s[l]==c)return ret=1,1; 42 else if(l==r)return ret=0,0; 43 re(i,1,4)re(j,1,4)if(a[c-‘A‘][qi[i]-‘A‘][qi[j]-‘A‘]) 44 re(k,l,r-1)if(dfs(l,k,qi[i])&&dfs(k+1,r,qi[j])) 45 return ret=1,1; 46 return ret=0,0; 47 } 48 int main() 49 { 50 Clear(aa,-1);Clear(a,0); 51 inin(W),inin(I),inin(N),inin(G); 52 re(i,1,W) 53 { 54 strin(ch); 55 a[‘W‘-‘A‘][ch[0]-‘A‘][ch[1]-‘A‘]=1; 56 } 57 re(i,1,I) 58 { 59 strin(ch); 60 a[‘I‘-‘A‘][ch[0]-‘A‘][ch[1]-‘A‘]=1; 61 } 62 re(i,1,N) 63 { 64 strin(ch); 65 a[‘N‘-‘A‘][ch[0]-‘A‘][ch[1]-‘A‘]=1; 66 } 67 re(i,1,G) 68 { 69 strin(ch); 70 a[‘G‘-‘A‘][ch[0]-‘A‘][ch[1]-‘A‘]=1; 71 } 72 strin(s+1); 73 int n=strlen(s+1);int bo=0; 74 if(dfs(1,n,‘W‘)){cout<<"W";bo=1;} 75 if(dfs(1,n,‘I‘)){cout<<"I";bo=1;} 76 if(dfs(1,n,‘N‘)){cout<<"N";bo=1;} 77 if(dfs(1,n,‘G‘)){cout<<"G";bo=1;} 78 if(!bo)cout<<"The name is wrong!"; 79 return 0; 80 }
标签:
原文地址:http://www.cnblogs.com/HugeGun/p/5269195.html