zoukankan      html  css  js  c++  java
  • 最长上升公共子序列

    #include<cstdio>
    #include<algorithm>
    using namespace std;

    const int maxn=5000;
    int a[maxn],b[maxn];
    int dp[maxn];

    int main(){
        int n;
        scanf("%d",&n);
        for (int i=1;i<=n;i++) scanf("%d",&a[i]);
        for (int i=1;i<=n;i++) scanf("%d",&b[i]);
        int ans=-1;
        int ti=0;
        for (int i=1;i<=n;i++){
            ti=0;
            for (int j=1;j<=n;j++){
                if(a[i]==b[j]){
                  dp[j]=max(dp[j],dp[ti]+1);
                  ans=max(ans,dp[j]);
                }
                else {
                    if(a[i]>b[j]) if(dp[j]>dp[ti]) ti=j;
                }
            }
        }
        printf("%d",ans);
    return 0;
    }

  • 相关阅读:
    JSONP
    函数式编程
    Cookie
    IE userData
    Web Storage
    前端学PHP之会话Session
    数据结构之归并排序
    数据结构之冒泡排序
    数据结构之插入排序
    数据结构之选择排序
  • 原文地址:https://www.cnblogs.com/lmjer/p/8559969.html
Copyright © 2011-2022 走看看