时间:2016-03-28 12:56:39 星期一
题目编号:[2016-03-28][POJ][1458][Common Subsequence]
题目大意:最长公共序列
#include <cstring>#include <iostream>#include <string>using namespace std;typedef long long LL;const int maxn = 1000 + 100;int dp[maxn][maxn];int main(){ string str1,str2; while(cin>>str1>>str2){ int m = str1.length(); int n = str2.length(); memset(dp,0,sizeof(dp)); for(int i = 0;i < m ; ++i){ for(int j = 0;j < n ; ++j){ if(str1[i] == str2[j] ){ dp[i+1][j+1] = dp[i][j] + 1; }else { dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]); } } } cout<<dp[m][n]<<'\n'; } return 0;}