Poj 2192 zipper

Source: Internet
Author: User

Today, I suddenly found out that I was not very impressed with this question, but I thought it was a classic question. So I decided to write a conclusion report.

The first question is to give you three strings. The first two strings can be constructed.
But you need to know that this condition is
They cannot change the order of the two final strings. </P> <p> two state equations are obtained.
DP [I] [J] indicates whether the first I character and the first J character constitute the first I + J characters of S3
(1)dp[i][j]=(dp[i-1][j]&&s1[i]==s3[i+j])?ture:flase
(2)dp[i][j]=(dp[i][j-1]&&s2[j==s3[i+j])?true:flase
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;char s1[500],s2[500],s3[500];int dp[500][500];int main(){    int t,i,j,k,len1,len2,len3,cas = 1 ;    scanf("%d",&t);    while(t--)    {        scanf("%s%s%s",s1+1,s2+1,s3+1);        len1 = strlen(s1+1);        len2 = strlen(s2+1);        len3 = strlen(s3+1);        memset(dp,0,sizeof(dp));        for(i = 1; i<=len1; i++)        {            if(s1[i] == s3[i])                dp[i][0] = 1;            else break;        }        for(i = 1; i<=len2; i++)        {            if(s2[i] == s3[i])                dp[0][i] = 1;            else break;        }        for(i = 1; i<=len1; i++)        {            for(j = 1; j<=len2; j++)            {                if(s3[i+j] == s1[i] && dp[i-1][j])                    dp[i][j] = 1;                if(s3[i+j] == s2[j] && dp[i][j-1])                    dp[i][j] = 1;            }        }        printf("Data set %d: ",cas++);        if(dp[len1][len2])            printf("yes\n");        else            printf("no\n");    }    return 0;}


Poj 2192 zipper

Related Keywords:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.