标签:
题目链接: HDU - 1501
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cstdlib> 5 #include<cmath> 6 #include<algorithm> 7 #define inf 0x7fffffff 8 using namespace std; 9 const int maxn=200+10; 10 11 int flag; 12 char s[maxn],s2[maxn],s3[maxn+maxn]; 13 int vis[maxn][maxn]; 14 int cnt,cnt2,cnt3,len,len2,len3; 15 16 void dfs(int sum,int x,int y) 17 { 18 if (sum >= len3) {flag=1;return ;} 19 if (s[x]!=s3[sum] && s2[y]!=s3[sum]) 20 return ; 21 if (vis[x][y]) return ; 22 vis[x][y]=1; 23 if (s[x]==s3[sum]) dfs(sum+1,x+1,y); 24 if (s2[y]==s3[sum]) dfs(sum+1,x,y+1); 25 return ; 26 } 27 28 int main() 29 { 30 int t,ncase=1; 31 while (scanf("%d",&t)!=EOF) 32 { 33 while (t--) 34 { 35 scanf("%s%s%s",s,s2,s3); 36 len=strlen(s); 37 len2=strlen(s2); 38 len3=strlen(s3); 39 flag=0; 40 memset(vis,0,sizeof(vis)); 41 if (s3[len3-1]==s[len-1]||s3[len3-1]==s2[len2-1]) 42 dfs(0,0,0); 43 if (flag) printf("Data set %d: yes\n",ncase++); 44 else printf("Data set %d: no\n",ncase++); 45 } 46 } 47 return 0; 48 }
标签:
原文地址:http://www.cnblogs.com/huangxf/p/4438410.html