Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
这个是dp,搜索可能超时哦,附代码#include<iostream> #include<cstdio> #include<cstring> #include<string> using namespace std; int main() { int t,num=1; string a,b,c; bool f[202][202]; scanf("%d",&t); while(t--) { cin>>a>>b>>c; cout<<"Data set "<<num++<<": "; int m=a.length(); int n=b.length(); int l=c.length(); if(m+n!=l) { cout<<"no"<<endl; continue; } memset(f,0,sizeof(f)); for(int i=0;i<=m;i++) { for(int j=0;j<=n;j++) { if(i==0&&j==0)f[i][j]=1; else { if(f[i-1][j]==1&&c[i+j-1]==a[i-1])f[i][j]=1; else if(f[i][j-1]==1&&c[i+j-1]==b[j-1])f[i][j]=1; } } } if(f[m][n]==1)cout<<"yes"<<endl; else cout<<"no"<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator