D - Catching Cheaters

题意:给 C 和 D 两个串

求 S(C,DS(C,D) as 4LCS(C,D)|C||D|4⋅LCS(C,D)−|C|−|D|

 

if(c[i] == d[i]) 贡献+2;

else 贡献 - 1;

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace std;
#define Pair pair<int, int>
#define ULL unsigned long long
#define LS l,mid,lson
#define RS mid+1,r,rson
#define MEM(a,x) memset(a,x,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define ll long long
#define N 1000005
#define EXP 1e-8
#define lowbit(x) (x&-x)
#define girlfriend zy
#define E exp(1.0)
//#define int long long
const int maxn = 100001;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
int dp[5001][5001];
char s1[5001];
char s2[5001];
int dp[5001][5001];
char s1[5001];
char s2[5001];
int main()
{
    int n,m;
    cin>>n>>m;
    cin>>s1+1>>s2+1; //脚标从1开始
    dp[0][0] = 0;
    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(s1[i] == s2[j])
            {
                dp[i][j] = max(0,dp[i-1][j-1]) + 2;
            }
            else
            {
                dp[i][j] = max(dp[i][j-1],dp[i-1][j]) - 1;
            }
            ans = max(dp[i][j],ans);
        }

    }
    cout<<ans<<endl;
}

 

posted @ 2020-11-16 13:11  Wh1te  阅读(132)  评论(2编辑  收藏  举报