题解 | #Coincidence#

Coincidence

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

#include <iostream>
using namespace std;

int dp[105][105];

int main() {
    string str1,str2;
    cin >> str1 >>str2;
    for(int i=0;i<str1.size()+1;i++){
        for(int j=0;j<str2.size()+1;j++){
            if(i==0||j==0){
                dp[i][j] = 0;
                continue;
            }
                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[str1.size()][str2.size()]<<endl;
}

全部评论

相关推荐

苍蓝星上艾露:这简历。。。可以试试我写的开源简历优化工具https://github.com/weicanie/prisma-ai
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-10 11:27
明天又是董事长面,啥时候是个头啊
在太阳里长大的人:公司就仨人吧😂
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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