zoukankan      html  css  js  c++  java
  • 哈尔滨理工大学软件与微电子学院第八届程序设计竞赛同步赛(高年级) E 小乐乐匹配字符串 【最长公共子序列】

    传送门:https://ac.nowcoder.com/acm/contest/301/E

    求最长公共子序列。

    立个 flag 搞dp。

    AC code:

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cmath>
    #define INF 0x3f3f3f3f
    using namespace std;
    const int MAXN = 1e3+10;
    char str1[MAXN], str2[MAXN];
    int dp[MAXN][MAXN];
    
    int main()
    {
        scanf("%s%s", &str1, &str2);
        memset(dp, 0, sizeof(dp));
        int len1 = strlen(str1);
        int len2 = strlen(str2);
            for(int i = 1; i <= len1; i++){
                for(int j = 1; j <= len2; j++){
                    if(str1[i-1] == str2[j-1]) {
                            dp[i][j] = max(dp[i-1][j-1]+1, dp[i][j]);
                    }
                    else{
                        dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
                    }
                }
            }
            printf("%d
    ", dp[len1][len2]);
    
        return 0;
    }
  • 相关阅读:
    转基因(转载)
    Diwali
    使用Matplotlib画图
    项目格式规范
    关于Dapper
    JQuery
    javascript封装
    2015年2月16日——作者观点
    2015年2月12日——不懂点
    在VS2013上使用git
  • 原文地址:https://www.cnblogs.com/ymzjj/p/10050565.html
Copyright © 2011-2022 走看看