soj 2796 Letter Deletion LCS

来源:互联网 发布:淘宝店铺怎么登录 编辑:程序博客网 时间:2024/06/03 21:03

题意:

删除后单词最长相等长度.

分析:

裸LCS.


code

#include <iostream>#include <cstdio>#include <cstring>#include <set>#include <map>#include <stack>#include <vector>#include <string>#include <queue>#include <cstdlib>#include <cmath>#include <algorithm>using namespace std;typedef pair<int, int> pii;typedef long long ull;typedef long long ll;typedef vector<int> vi;#define xx first#define yy second#define rep(i, a, n) for (int i = a; i < n; i++)#define sa(n) scanf("%d", &(n))#define vep(c) for(decltype((c).begin()) it = (c).begin(); it != (c).end(); it++)const int mod = int(1e9) + 7, INF = 0x3fffffff, maxn = 1e5 + 12;int dp[222][222];int main(void){    string a, b;    while (cin >> a >> b) {        for (int i = 1; i <= a.size(); i++) {            for (int j = 1; j <= b.size(); j++) {                dp[i][j] = max(dp[i - 1][j], max(dp[i][j - 1], dp[i - 1][j - 1] + (a[i - 1] == b[j - 1] ? 1 : 0)));            }        }        cout << dp[a.size()][b.size()] << endl;    }    return 0;}
0 0
原创粉丝点击