zoukankan      html  css  js  c++  java
  • [tyvj 1071] LCIS

    题目描述
    熊大妈的奶牛在小沐沐的熏陶下开始研究信息题目。小沐沐先让奶牛研究了最长上升子序列,再让他们研究了最长公共子序列,现在又让他们要研究最长公共上升子序列了。
    小沐沐说,对于两个串A,B,如果它们都包含一段位置不一定连续的数字,且数字是严格递增的,那么称这一段数字是两个串的公共上升子串,而所有的公共上升子串中最长的就是最长公共上升子串了。
    奶牛半懂不懂,小沐沐要你来告诉奶牛什么是最长公共上升子串。不过,只要告诉奶牛它的长度就可以了。
    输入格式
    第一行N,表示A,B的长度。
    第二行,串A。
    第三行,串B。
    输出格式
    输出长度。

    提示
    1<=N<=3000,A,B中的数字不超过maxlongintMoe-ing

    样例数据
    输入样例 #1
    4
    2 2 1 3
    2 1 2 3
    输出样例 #1
    2

    //By Menteur_Hxy
    #include<cstdio>
    #include<iostream>
    using namespace std;
    
    const int MAX=3010;
    int n,m,top;
    int a[MAX],b[MAX],f[MAX][MAX];
    
    int main() {
        scanf("%d",&n);
        for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    //  scanf("%d",&m);
        for(int i=1;i<=n;i++) scanf("%d",&b[i]);
        for(int i=1;i<=n;i++){
            int maxn=0;
            for(int j=1;j<=n;j++) {
                if(a[i]!=b[j]) f[i][j]=f[i-1][j];
                else f[i][j]=maxn+1;
                if(a[i]>b[j]) maxn=max(maxn,f[i-1][j]);
            }
        }
        int ans=0;
        for(int i=1;i<=n;i++)
            ans=max(ans,f[n][i]);
        printf("%d",ans);
        return 0;   
    }
    版权声明:本文为博主原创文章,未经博主允许不得转载。 博主:https://www.cnblogs.com/Menteur-Hxy/
  • 相关阅读:
    linux修改时间
    关于PGSQL连接问题
    windows与linux的文件路径
    node js 判断数组中是否包含某个值
    cmd设置utf8编码
    Spring异步请求处理
    Spring任务执行和任务调度
    Tomcat线程池配置
    Apache HttpClient和HttpAsyncClient应用
    FreeMarker导出复杂Excel
  • 原文地址:https://www.cnblogs.com/Menteur-Hxy/p/9248007.html
Copyright © 2011-2022 走看看