标签:des style http color os io for ar
3 cat tree tcraete cat tree catrtee cat tree cttaree
Data set 1: yes Data set 2: yes Data set 3: no
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<limits.h> typedef long long LL; using namespace std; const int maxn=220; char s1[maxn],s2[maxn],s[maxn<<1]; int dp[maxn][maxn]; int len,len1,len2; int t; int dfs(int i,int j,int k) { if(k==len) return 1; if(dp[i][j]) return 0; dp[i][j]=1; if(s1[i]==s[k]) { if(dfs(i+1,j,k+1)) return 1; } if(s2[j]==s[k]) { if(dfs(i,j+1,k+1)) return 1; } return 0; } int main() { int l=0; scanf("%d",&t); while(t--) { scanf("%s%s%s",s1,s2,s); len1=strlen(s1); len2=strlen(s2); len=strlen(s); memset(dp,0,sizeof(dp)); if(dfs(0,0,0)) printf("Data set %d: yes\n",++l); else printf("Data set %d: no\n",++l); } return 0; }
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<limits.h> using namespace std; const int maxn=220; char s1[maxn],s2[maxn],s[maxn<<1]; int dp[maxn][maxn]; int main() { int t; int l=0; scanf("%d",&t); getchar(); while(t--) { scanf("%s%s%s",s1+1,s2+1,s+1); int len1=strlen(s1+1); int len2=strlen(s2+1); int len=strlen(s+1); memset(dp,0,sizeof(dp)); dp[0][0]=1; for(int i=0;i<=len1;i++) { for(int j=0;j<=len2;j++) { if(i==0&&j==0) continue; if(s[i+j]==s1[i]&&i&&dp[i-1][j]) dp[i][j]=1; if(s[i+j]==s2[j]&&j&&dp[i][j-1]) dp[i][j]=1; } } if(dp[len1][len2]) printf("Data set %d: yes\n",++l); else printf("Data set %d: no\n",++l); } return 0; }
HUD 1501 Zipper(记忆化 or DP),布布扣,bubuko.com
标签:des style http color os io for ar
原文地址:http://www.cnblogs.com/mfrbuaa/p/3919752.html