Common Subsequence poj 1548

题目连接:http://poj.org/problem?id=1458

水题不解释

代码:

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int maxn=300;

int dp[maxn][maxn];
int main(){
    char a[maxn],b[maxn];
    while(scanf("%s%s",a+1,b+1)!=EOF){
        int lena=strlen(a+1);
        int lenb=strlen(b+1);
        //cout<<lena<<"\t"<<lenb<<endl;
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=lena;++i){
            for(int j=1;j<=lenb;++j){
                if(a[i]==b[j]){
                    dp[i][j]=dp[i-1][j-1]+1;
                }else{
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }
        printf("%d\n",dp[lena][lenb]);
    }
    return 0;
}


你可能感兴趣的:(Common Subsequence poj 1548)