zoukankan      html  css  js  c++  java
  • FZU 1502 Letter Deletion(DP)

    Description

    You are given two words (each word consists of upper-case English letters). 

    Try to delete some letters from each word so that the resulting words are equal. 

    What is the maximum possible length of the resulting word?

    Input

    There will be no more than 10 test cases. 

    Each test case consists of a single line, contaning the two words separated by a single space. The length of each of these words is between 1 and 200.

    Output

    For each test case output the maximum length of a resulting word (the length of the longest word that can be created from both words by removing some letters). 

    If the two words have no letters in common, output 0.

    Sample Input

    AAABBB ABABAB
    AXYAAZ CCCXCCCYCCCZCC
    ABCDE EDCBA
    

    Sample Output

    4
    3
    1
    #include<stdio.h>
    #include<iostream>
    #include<string.h>
    #include<math.h>
    using namespace std;
    char a[300],b[300];
    int dp[300][300];
    int main()
    {
        int len1,len2;
        int i,j;
        while(scanf("%s%s",a,b)!=EOF)
        {
            
            len1=strlen(a);
            len2=strlen(b);
            for(i=0;i<len1;i++)
            dp[i][0]=0;
            for(j=0;j<len2;j++)
            dp[0][j]=0;
            for(i=1;i<=len1;i++)
            for(j=1;j<=len2;j++)
            {
                if(a[i-1]==b[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
                else
                {
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                }
            }
            cout<<dp[len1][len2]<<endl;
        }
        return 0;
    }
  • 相关阅读:
    解题报告:POJ1852 Ants
    解题报告:POJ2573 Bridge(分析建模)
    POJ 3321 Apple Tree(树状数组模板)
    PAT1139 First Contact
    POJ3259 SPFA判定负环
    HDOJ2586 最近公共祖先模板
    树的直径与最近公共祖先
    字符数组_随机存储
    青鸟资料下载
    软件测试(4)_LoadRunner使用
  • 原文地址:https://www.cnblogs.com/Annetree/p/5735263.html
Copyright © 2011-2022 走看看