• 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;
    }
  • 相关阅读:
    Lock、Synchronized锁解析
    js多个计时器互不影响触发
    php Excel文件导入 Spreadsheet_Excel_Reader
    Tcp/ip简介
    对称加密和非对称加密
    AFNetworking 3.0迁移指南
    从 Objective-C 里的 Alloc 和 AllocWithZone 谈起
    iOS 沙盒
    SDWebImage解析
    dSYM文件
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5904908.html
Copyright © 2020-2023  润新知