zoukankan      html  css  js  c++  java
  • HDU 5489 二分 LIS

    Removed Interval

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 1703    Accepted Submission(s): 558


    Problem Description
    Given a sequence of numbers A=a1,a2,,aN , a subsequence b1,b2,,bk of A is referred as increasing if b1<b2<<bk . LY has just learned how to find the longest increasing subsequence (LIS).
    Now that he has to select L consecutive numbers and remove them from A for some mysterious reasons. He can choose arbitrary starting position of the selected interval so that the length of the LIS of the remaining numbers is maximized. Can you help him with this problem?
     
    Input
    The first line of input contains a number T indicating the number of test cases (T100 ).
    For each test case, the first line consists of two numbers N and L as described above (1N100000,0LN ). The second line consists of N integers indicating the sequence. The absolute value of the numbers is no greater than 109 .
    The sum of N over all test cases will not exceed 500000.
     
    Output
    For each test case, output a single line consisting of “Case #X: Y”. X is the test case number starting from 1. Y is the maximum length of LIS after removing the interval.
     
    Sample Input
    2 5 2 1 2 3 4 5 5 3 5 4 3 2 1
     
    Sample Output
    Case #1: 3 Case #2: 1
     
    Source
    题意:给你长度为n的序列  现在删除长度为L的连续的一段   问如何删除使得剩下的部分的LIS最大 输出最大值
    题解:先处理一遍LIS dp[i]  表示以a[i]结尾的最长上升子序列的长度  对于每一段的长度L  ans=dp[i]+{i+L之后的以大于a[i]的值为起点的最长上升的长度}
    与网上题解不同 这里是倒着来的。
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<cstring>
     5 #include<algorithm>
     6 #include<map>
     7 #include<queue>
     8 #include<stack>
     9 #include<vector>
    10 #include<bitset>
    11 #include<set>
    12 #define ll __int64
    13 #define mod 100000000
    14 #define N 5e6+10
    15 #define M 1e
    16 using namespace std;
    17 int t;
    18 int n,l;
    19 int a[100005],b[100005];
    20 int dp[100005];
    21 int ans[100005];
    22 int main()
    23 {
    24     scanf("%d",&t);
    25     for(int i=1;i<=t;i++)
    26     {
    27         scanf("%d %d",&n,&l);
    28         a[0]=0;
    29         for(int j=1;j<=n;j++){
    30             scanf("%d",&a[j]);
    31             b[j]=-a[j];
    32         }
    33         int exm=1;
    34         ans[exm]=a[1];
    35         dp[1]=1;
    36         for(int j=2;j<=n;j++)
    37         {
    38             if(a[j]>ans[exm]){
    39                 exm++;
    40                 ans[exm]=a[j];
    41                 dp[j]=exm;
    42             }
    43             else
    44             {
    45                 int pos=lower_bound(ans+1,ans+exm,a[j])-ans;
    46                 ans[pos]=a[j];
    47                 dp[j]=pos;
    48             }
    49         }
    50         int an=0;
    51         for(int j=0;j<=n;j++)
    52            ans[j]=1e9;
    53         int re=0;
    54         for(int j=n-l;j>=1;j--)
    55         {
    56             int x=lower_bound(ans,ans+n,b[j])-ans;//
    57             an=max(an,dp[j]+x);
    58             int y=lower_bound(ans,ans+n,b[j+l])-ans;
    59             ans[y]=b[j+l];
    60             re=max(re,y+1);
    61         }
    62        printf("Case #%d: %d
    ",i,max(an,re));
    63     }
    64     return 0;
    65 }
    66 /*
    67 6
    68 6 2
    69 1 3 5 7 2 4
    70 */
  • 相关阅读:
    hmset
    java 调用mongo 判断大于等于 并且小约等于<=
    Maven项目,别人的没问题,自己机器一直有问题
    linux 时间datetimectl 问题
    真正手把手教 git
    0324-SQLMAP使用参数备注
    安全推荐网址:
    JavaScript Base64 作为文件上传的实例代码解析
    学习笔记|变量的解构赋值
    学习笔记|let 和 const 命令
  • 原文地址:https://www.cnblogs.com/hsd-/p/7118690.html
Copyright © 2011-2022 走看看