POJ1458【最长公共子序列】

基础DP。

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
const double pi = acos(-1.0);

const int mod =9973;

const int N = 1e3+10;

char s1[N],s2[N];
int dp[N][N];

int main()
{
    while(~scanf("%s%s",s1+1,s2+1))
    {
        int len1,len2;
        len1=strlen(s1+1);
        len2=strlen(s2+1);
        memset(dp,0,sizeof(dp));

        for(int i=1;i<=len1;++i)
        {
            for(int j=1;j<=len2;j++)
            {
                if(s1[i]==s2[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
",dp[len1][len2]);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/keyboarder-zsq/p/5934479.html