zoukankan      html  css  js  c++  java
  • HDU5489 LIS变形

    Removed Interval


    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
     
    题意:一个含有n个元素的数组,删去k个连续数后,求LIS
    题解:定义l[i]为  以第i个数结尾,删除i-k-1到i-1这k个数的LIS
            定义r[i]为 以i开头到n的LIS
           因为这样我们会忽略删除最后K个数的情况,所以我们n+1   最后一个元素赋值为无穷大
           答案就是 l[i]+r[i]-2;
    ///1085422276
    
    #include<bits/stdc++.h>
    using namespace std;
    //#pragma comment(linker, "/STACK:102400000,102400000")
    using namespace std ;
    typedef long long ll;
    #define mem(a) memset(a,0,sizeof(a))
    #define pb push_back
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){
            if(ch=='-')f=-1;ch=getchar();
        }
        while(ch>='0'&&ch<='9'){
            x=x*10+ch-'0';ch=getchar();
        }return x*f;
    }
    //****************************************
    const int  N=100000+50;
    #define mod 1000000007
    #define inf 1000000007
    
    int b[N],a[N],dp[N],l[N],r[N],n,L;
    
    int main() {
      int T=read();int oo=1;
      while(T--) {
         mem(a),mem(b);
         scanf("%d%d",&n,&L);
         for(int i=1;i<=n;i++) {
            scanf("%d",&a[i]);
         }a[++n]=inf;
         for(int i=1;i<=n;i++) {
            b[n-i+1]=-a[i];
         }
         fill(dp+1,dp+n+1,inf+2);
         for(int i=L+1;i<=n;i++) {
            int tmp=lower_bound(dp+1,dp+n+1,a[i])-dp;
            l[i]=tmp;
            tmp=lower_bound(dp+1,dp+n+1,a[i-L])-dp;
            dp[tmp]=a[i-L];
         }
         fill(dp+1,dp+n+1,inf);
         for(int i=1;i<=n;i++) {
            int tmp=lower_bound(dp+1,dp+n+1,b[i])-dp;
            r[n-i+1]=tmp;
            dp[tmp]=b[i];
         }
         //for(int i=1;i<=n;i++)cout<< l[i]<<" ";
         //cout<<endl;
         //for(int i=1;i<=n;i++)cout<< r[i]<<" ";
         int ans=0;
         for(int i=L+1;i<=n;i++) {
            ans=max(ans,l[i]+r[i]-2);
         }
         printf("Case #%d: ",oo++);
         cout<<ans<<endl;
      }
      return 0;
    }
    代码
  • 相关阅读:
    创建SSIS包—ETL中典型的数据清洗
    SSIS中的容器和数据流—数据转换(Transformations)
    创建SSIS包—循环和动态package
    SSIS中的容器和数据流—数据转换(Transformations)续
    创建SSIS包—建立端到端的package
    SQL点滴9—SQL Server中的事务处理以及SSIS中的内建事务
    SSIS中的容器和数据流—调试工具数据视图
    SQL点滴11—重置win7登录密码影响SQL登录
    SQL点滴10—使用with语句来写一个稍微复杂sql语句,附加和子查询的性能对比
    SSIS中的容器和数据流—举例说明数据转换任务
  • 原文地址:https://www.cnblogs.com/zxhl/p/4952511.html
Copyright © 2011-2022 走看看