题解 | #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;
    }
    
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-03 18:13
点赞 评论 收藏
分享
点赞 评论 收藏
分享
仁者伍敌:牛子这些人还会点一个自动回复,boss都不带回复的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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