首页 > 其他 > 详细

CodeForces - Problem 1447 - Catching Cheaters - DP

时间:2020-11-17 15:58:34      阅读:21      评论:0      收藏:0      [点我收藏+]

CodeForces - Problem 1447 - Catching Cheaters - DP

技术分享图片

#include <bits/stdc++.h>
using namespace std;
const int N = 5000+5;
char a[N],b[N];
int dp[N][N]; 
// Let DP[i][j] be the maximum similarity score if we end the first substring with Ai and the second substring with Bj.
int main(){
    int ans=0;
    int n,m;
    scanf("%d%d",&n,&m);
    scanf("%s%s",a+1,b+1);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i]==b[j]){
                dp[i][j]=max(2,dp[i-1][j-1]+2); // 2 represent only a[i] and b[j]
            }else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1])-1;
            }
            ans=max(ans,dp[i][j]);
        }
    } 

    printf("%d",ans);
    system("pause");
    return 0;
}

CodeForces - Problem 1447 - Catching Cheaters - DP

原文:https://www.cnblogs.com/popodynasty/p/13993556.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!