• UVa 10405 Longest Common Subsequence(LCS)


    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    
    #define max(a,b) (((a) > (b)) ? (a) : (b))
    
    const int MAXN = 1010;
    char s[MAXN], d[MAXN];
    int dp[MAXN][MAXN];
    
    int main()
    {
        while (gets(s+1) && gets(d+1))
        {
            int ls = strlen(s + 1);
            int ld = strlen(d + 1);
    
            memset(dp, 0, sizeof(dp));
            for (int i = 1; i <= ls; ++i)
                for (int j = 1; j <= ld; ++j)
                    if (s[i] == d[j])
                        dp[i][j] = dp[i-1][j-1] + 1;
                    else
                        dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
    
            printf("%d\n", dp[ls][ld]);
        }
        return 0;
    }
    -------------------------------------------------------

    kedebug

    Department of Computer Science and Engineering,

    Shanghai Jiao Tong University

    E-mail: kedebug0@gmail.com

    GitHub: http://github.com/kedebug

    -------------------------------------------------------

  • 相关阅读:
    pm2
    php 基础知识
    EBADF, read
    php apache
    noah
    ejs
    node linux
    枚举系统进程
    c++ 进程权限的提升
    Liunx的目录结构
  • 原文地址:https://www.cnblogs.com/kedebug/p/2765332.html
Copyright © 2020-2023  润新知