AcWing 897. 最长公共子序列 C
原题链接
简单
作者:
LaChimere
,
2021-06-04 15:05:17
,
所有人可见
,
阅读 258
C
#include <stdio.h>
#define MAXSIZE 1010
#define max(a,b) ((a)>(b)?(a):(b))
int n, m, dp[MAXSIZE][MAXSIZE];
char a[MAXSIZE], b[MAXSIZE];
void init() {
scanf("%d%d", &n, &m);
scanf("%s%s", a+1, b+1);
}
int main() {
init();
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
if (a[i] == b[j]) {
dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1);
}
}
}
printf("%d\n", dp[n][m]);
return 0;
}