题解 | #Coincidence#

Coincidence

https://www.nowcoder.com/practice/f38fc44b43cf44eaa1de407430b85e69

// 最长公共子序列
#include<bits/stdc++.h>
using namespace std;
const int maxn=101;
string str1,str2;
int main(){
    while (cin>>str1>>str2)
    {
        int m=str1.size();int n=str2.size();
        int dp[maxn][maxn];
        memset(dp, 0, sizeof(dp));
        for (int i = 1; i <= m; i++)
        {
            for (int j = 1; j <= n; j++)
            {

                if(str1[i-1]==str2[j-1])
                    dp[i][j]=dp[i-1][j-1]+1;
                else
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
            
        }
        cout<<dp[m][n]<<endl;
    }
    
}

全部评论

相关推荐

10-17 23:18
已编辑
西北农林科技大学 Web前端
独行m:给25可以试试,但他只能给12,那就是纯纯的事精
秋招,不懂就问
点赞 评论 收藏
分享
10-14 12:20
门头沟学院 Java
迷茫的大四🐶:摊牌了,我是25届的,你们也不招我
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务