Combine String

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef unsigned long long LL;
#define met(a,b) (memset(a,b,sizeof(a)))
const int INF = 1e9+7;
const int N = 2100;
const int MOD = 9973;

int dp[N][N];

int main()
{
    char s1[N], s2[N], s[N*2];

    while(scanf("%s%s%s", s1+1, s2+1, s+1)!=EOF)
    {
        int len1=strlen(s1+1), len2=strlen(s2+1), i, j;
        int len = strlen(s+1);

        ///printf("%d %d %d\n", len1, len2, len);

        if(len1+len2!=len)
        {
            printf("No\n");
            continue;
        }

        met(dp, 0);
        dp[0][0] = 1;
        for(i=0; i<=len1; i++)
        for(j=0; j<=len2; j++)
        {
            if(i==0 && j==0) continue;
            if(s1[i]==s[i+j] && dp[i-1][j] && !dp[i][j])
                dp[i][j] = dp[i-1][j];
            if(s2[j]==s[i+j] && dp[i][j-1] && !dp[i][j])
                dp[i][j] = dp[i][j-1];
        }

        /**
        for(i=0; i<=len1; i++)
        for(j=0; j<=len2; j++)
        {
            printf("%d%c", dp[i][j], j==len2?'\n':' ');
        }

        */

        if(dp[len1][len2]) printf("Yes\n");
        else   printf("No\n");
    }
    return 0;
}
View Code

 

posted on 2016-05-28 12:54  栀蓝  阅读(737)  评论(0编辑  收藏  举报

levels of contents