• 线性DP codevs2185 最长公共上升子序列


    2185 最长公共上升子序列

    题目描述 Description

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

    输入描述 Input Description

    第一行N,表示A,B的长度。
    第二行,串A。
    第三行,串B。

    输出描述 Output Description

    输出长度。

    样例输入 Sample Input

    4
    2 2 1 3
    2 1 2 3

    样例输出 Sample Output

    2

    数据范围及提示 Data Size & Hint

    1<=N<=3000,A,B中的数字不超过maxlongint

    LCIS问题

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 using namespace std;
     6 int n;
     7 int a[3010],b[3010],f[3010];
     8 int main(){
     9     scanf("%d",&n);
    10     for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    11     for(int i=1;i<=n;i++) scanf("%d",&b[i]);
    12     int k=0;
    13     for(int i=1;i<=n;i++){
    14         k=0;    
    15         for(int j=1;j<=n;j++){
    16             if(a[i]==b[j]&&f[k]+1>f[j]) f[j]=f[k]+1;
    17             if(a[i]>b[j]&&f[k]<f[j]) k=j; 
    18         }
    19     }
    20     int ans=-0x80000000;
    21     for(int i=1;i<=n;i++) ans=max(ans,f[i]);
    22     printf("%d
    ",ans);
    23     return 0;
    24 }
  • 相关阅读:
    puppet master/agent
    puppet单机模型
    Nginx MogileFS 配置
    mogilefs 安装与配置
    CMakeLists.txt
    下载安装MariaDB Galera 10.1
    BZOJ1295: [SCOI2009]最长距离
    BZOJ2375: 疯狂的涂色
    BZOJ1260: [CQOI2007]涂色paint
    BZOJ2789: [Poi2012]Letters
  • 原文地址:https://www.cnblogs.com/zwube/p/7108074.html
Copyright © 2020-2023  润新知