- 最长公共子序列
为啥过不了呢
- 2023-8-15 13:05:24 @
#define _CRT_SECURE_NO_WARNINGS//scanf C4996 报错忽略
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 210;
char a[N], b[N];
int f[N][N], n, m;
int lcs()
{
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j)
if (a[i] == b[j]) f[i][j] = f[i - 1][j - 1] + 1;
else f[i][j] = max(f[i - 1][j], f[i][j - 1]);
}
return f[n][m];
}
int main()
{
while (scanf("%s%s", a + 1, b + 1) != EOF) {
n=strlen(a+1), m=strlen(b + 1);
memset(f, 0, sizeof(f));
cout << lcs();
}
return 0;
}
// Path: luogu\no_2.cpp
3 comments
-
经开一中2026届11班关泽瑞 LV 6 @ 2024-11-26 19:10:37
哈喽,我刚刚创建了一个房间,有点寂寞无聊,可否敢跟我一战!点击下方链接打开就可以跟我一决高下。 https://chess.z3web.cn/p?r=237538&p=1234 --象棋在线游玩
-
2023-8-19 14:56:25@
没换行。。。
👍 1 -
2023-8-15 13:07:25@
样例可以过,评测乱七八糟的
- 1
Information
- ID
- 510
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 6
- Tags
- (None)
- # Submissions
- 25
- Accepted
- 10
- Uploaded By