zoukankan      html  css  js  c++  java
  • HDU-1159-Common Subsequence

    链接:https://vjudge.net/problem/HDU-1159#author=0

    题意:

    最长公共子序列,LCS

    思路:

    LCS

    代码:

    #include <iostream>
    #include <memory.h>
    #include <vector>
    #include <map>
    #include <algorithm>
    #include <cstdio>
    #include <math.h>
    #include <queue>
    #include <string>
    #include <stack>
    
    using namespace std;
    
    typedef long long LL;
    
    const int MAXN = 1000 + 10;
    
    int dp[MAXN][MAXN];
    
    int main()
    {
        string a, b;
        while (cin >> a >> b)
        {
            memset(dp, 0, sizeof(dp));
            int lena = (int)a.length();
            int lenb = (int)b.length();
            for (int i = 1;i <= lena;i++)
            {
                for (int j = 1;j <=  lenb;j++)
                {
                    if (a[i - 1] == b[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[lena][lenb] << endl;
        }
    
        return 0;
    }
    

      

  • 相关阅读:
    练习5.6.3节
    size_t
    练习3.43
    use include to read a file
    ACM数学(转)
    POJ 2039 To and Fro
    poj 1716 差分约束
    poj 3159 差分约束
    hdu 4571 floyd+动态规划
    poj 1364 差分约束
  • 原文地址:https://www.cnblogs.com/YDDDD/p/10630128.html
Copyright © 2011-2022 走看看