• D


    题意:给 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;
    }
  • 相关阅读:
    2017-7-17/18 背包dp cf round 417 div2
    poj3667-Hotel-线段树-区间合并
    STL 总结
    c++ 用freopen简单的重定向,再也不怕debug了~
    dynamic programming 从入门到放弃
    java 输入数据
    数位dp
    ECJTU 2018 Summer Training 5
    ECJTU 2018 Summer Training 2
    dfs和bfs专题
  • 原文地址:https://www.cnblogs.com/lightWh1te/p/13984594.html
Copyright © 2020-2023  润新知