Create 1501_CSDN_dp.cpp

pull/2/head
Kirigaya Kazuto 2016-04-21 18:38:36 +08:00
parent 307c718136
commit 1a9026bc58
1 changed files with 42 additions and 0 deletions

42
HDOJ/1501_CSDN_dp.cpp Normal file
View File

@ -0,0 +1,42 @@
#include <cstdio>
#include <cstring>
//#define LOCAL
using namespace std;
const int MAXN=205;
char a[MAXN],b[MAXN],all[2*MAXN-5];
int lenA,lenB,lenAll;
bool DFS(int posA,int posB,int posAll) {
if(posA==lenA&&posB==lenB)
return true;
if(posA<lenA&&a[posA]==all[posAll]&&DFS(posA+1,posB,posAll+1))
return true;
if(posB<lenB&&b[posB]==all[posAll]&&DFS(posA,posB+1,posAll+1))
return true;
return false;
}
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif
int T,cnt=0;
scanf("%d",&T);
while(T--) {
printf("Data set %d: ",++cnt);
scanf("%s%s%s",a,b,all);
lenA=strlen(a);
lenB=strlen(b);
lenAll=strlen(all);
if((all[0]!=a[0]&&all[0]!=b[0])||(all[lenAll-1]!=a[lenA-1]&&all[lenAll-1]!=b[lenB-1])) {//剪枝不加上就会TLE
printf("no\n");
continue;
}
printf("%s\n",DFS(0,0,0)?"yes":"no");
}
return 0;
}