https://cn.vjudge.net/problem/HDU-5707
Given three strings aa, bb and cc, your mission is to check whether cc is the combine string of aa and bb.
A string cc is said to be the combine string of aa and bb if and only if cc can be broken into two subsequences, when you read them as a string, one equals to aa, and the other equals to bb.
For example, ``adebcf'' is a combine string of ``abc'' and ``def''.
Input
Input file contains several test cases (no more than 20). Process to the end of file.
Each test case contains three strings aa, bb and cc (the length of each string is between 1 and 2000).
Output
For each test case, print ``Yes'', if cc is a combine string of aa and bb, otherwise print ``No''.
Sample Input
abc def adebcf abc def abecdf
Sample Output
Yes No
dp[i][j]代表a串前i个字符与b串前j个字符能否拼出c串前(i+j)个字符
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<list>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;
char a[2005],b[2005],c[2005];
bool dp[2005][2005];
int main(){
while(~scanf("%s%s%s",a+1,b+1,c+1)){
memset(dp,0,sizeof(dp));
int la=strlen(a+1);
int lb=strlen(b+1);
int lc=strlen(c+1);
dp[0][0]=1;
for(int i=0;i<=la;i++){
for(int j=0;j<=lb;j++){
if(i+j>=0&&i+j<=lc){
if(c[i+j]==a[i]&&i) dp[i][j]=dp[i][j]||dp[i-1][j];
if(c[i+j]==b[j]&&j) dp[i][j]=dp[i][j]||dp[i][j-1];
}
}
}
if(la+lb==lc&&dp[la][lb]) printf("Yes\n");
else printf("No\n");
}
return 0;
}