#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

  • 1

Information

ID
510
Time
1000ms
Memory
256MiB
Difficulty
6
Tags
(None)
# Submissions
25
Accepted
10
Uploaded By