zoukankan      html  css  js  c++  java
  • HDU 5904 LCIS

    $dp$。

    这题的突破口在于要求数字是连续的。

    可以分别记录两个串以某个数字为结尾的最长上升长度,然后枚举一下以哪个数字为结尾就可以得到答案了。

    因为$case$有点多,不能每次$memset$,额外开一个数组记录一下这组$case$中数字有没有出现过。

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<iostream>
    using namespace std;
    typedef long long LL;
    const double pi=acos(-1.0),eps=1e-6;
    void File()
    {
        freopen("D:\in.txt","r",stdin);
        freopen("D:\out.txt","w",stdout);
    }
    template <class T>
    inline void read(T &x)
    {
        char c=getchar(); x=0;
        while(!isdigit(c)) c=getchar();
        while(isdigit(c)) {x=x*10+c-'0'; c=getchar();}
    }
    
    const int maxn=100010;
    int dp[10*maxn],f[10*maxn],n,m;
    int s1[10*maxn],s2[10*maxn];
    
    int main()
    {
        int T; scanf("%d",&T);
        for(int cas=1;cas<=T;cas++)
        {
            dp[0]=0; f[0]=0; s1[0]=cas; s2[0]=cas;
            scanf("%d%d",&n,&m);
            for(int i=1;i<=n;i++)
            {
                int x; scanf("%d",&x);
                if(s1[x]<cas) s1[x]=cas, dp[x]=0;
                if(s1[x-1]<cas) dp[x-1]=0;
                dp[x]=max(dp[x],dp[x-1]+1);
            }
            int ans=0;
            for(int i=1;i<=m;i++)
            {
                int x; scanf("%d",&x);
                if(s2[x]<cas) s2[x]=cas, f[x]=0;
                if(s2[x-1]<cas) f[x-1]=0;
                f[x]=max(f[x],f[x-1]+1);
                if(s1[x]<cas) dp[x]=0;
                int pp=min(f[x],dp[x]);
                ans=max(ans,pp);
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    kubuntu设置
    odoo git环境搭建
    ubuntu Gnome 14.10添加打印机
    ubuntu 14.10安装Balsamiq Mockups
    elementary os luna安装配置
    OpenERP QWeb模板标签笔记
    pycharm3 注册码
    统计项目代码
    odoo filter 日期
    opencart 安装
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5904908.html
Copyright © 2011-2022 走看看