HDU 1159 LCS最长公共子序列

时间:2022-06-20 10:54:02
 #include <cstdio>
#include <cstring> using namespace std;
const int N = ;
#define max(a,b) a>b?a:b char a[N] , b[N];
int dp[N][N]; int main()
{
while(scanf("%s%s" , a+ , b+) != EOF){
int l1 = strlen(a+);
int l2 = strlen(b+);
for(int i = ; i<=l1 ; i++)
for(int j = ; j<=l2 ; j++){
if(a[i] == b[j]) dp[i][j] = dp[i-][j-]+;
else dp[i][j] = max(dp[i-][j] , dp[i][j-]);
}
printf("%d\n" , dp[l1][l2]);
}
return ;
}