Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这个是dp,搜索可能超时哦,附代码

Posted by 1004115224 at 2012-08-26 14:47:48 on Problem 2192
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator