HDU 1159 Common Subsequence

来源:互联网 发布:装修软件 编辑:程序博客网 时间:2024/05/16 17:38


http://write.blog.csdn.net/postedit

#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;const int N = 1010;int dp[N][N];char s1[N],s2[N];int main(){//    freopen("in.txt", "r", stdin);    while(cin >> s1 >> s2){        memset(dp, 0, sizeof(dp));        int l1 = strlen(s1), l2 = strlen(s2);        for(int i=0; i<l1; i++){            for(int j=0; j<l2; j++){                if(s1[i] == s2[j])                    dp[i+1][j+1] = dp[i][j] + 1;                else                    dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);            }        }        printf("%d\n",dp[l1][l2]);    }    return 0;};

0 0