标签:ase while pid case fine == int cst search
转载请注明出处:http://blog.csdn.net/u012860063
题目链接
HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1501
POJ: http://poj.org/problem?id=2192
Description
Input
Output
Sample Input
3 cat tree tcraete cat tree catrtee cat tree cttaree
Sample Output
Data set 1: yes Data set 2: yes Data set 3: no
Source
题意:就是找在不变换字符串1和字符串2的字母的顺序的情况下,是否能组成字符串3。
代码例如以下:
#include <cstdio> #include <cstring> #define N 247 char a[N], b[N], c[N+N]; int len1, len2, len3; int dfs(int x, int y, int sum) { if(sum >len3) return 1; if(a[x]!=c[sum] && b[y]!=c[sum]) return 0; if(a[x]==c[sum] && dfs(x+1,y,sum+1)) return 1; if(b[y]==c[sum] && dfs(x,y+1,sum+1)) return 1; return 0; } int main() { int t, cas = 0; while(~scanf("%d",&t)) { while(t--) { scanf("%s%s%s",a+1,b+1,c+1);//从字符串下标为1開始输入 len1 = strlen(a+1); len2 = strlen(b+1); len3 = strlen(c+1); int flag = 0; if(c[len3]==a[len1] || c[len3]==b[len2])//优化,假设C最后的字母是a的最后一个 { //或者b的最后一个才有可能是由它们组成的 flag = dfs(1, 1, 1); } if(flag == 1) printf("Data set %d: yes\n",++cas); else printf("Data set %d: no\n",++cas); } } return 0; }
hdu1501&&poj2192 Zipper(DFS)
标签:ase while pid case fine == int cst search
原文地址:http://www.cnblogs.com/wgwyanfs/p/6752745.html