hdoj5489Removed Interval【lis】
来源:互联网 发布:最优化理论 推荐教材 编辑:程序博客网 时间:2024/06/07 06:39
Removed Interval
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1282 Accepted Submission(s): 437
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 selectL 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?
Now that he has to select
Input
The first line of input contains a number T indicating the number of test cases (T≤100 ).
For each test case, the first line consists of two numbersN and L as described above (1≤N≤100000,0≤L≤N ). 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.
For each test case, the first line consists of two numbers
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
25 21 2 3 4 55 35 4 3 2 1
Sample Output
Case #1: 3Case #2: 1
#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<list>#include<vector>using namespace std;const int maxn=100010;int dp[maxn];int li[maxn],ri[maxn],num[maxn];/**********定义li[i]为在前i位删除[x-l-1,x-1]的lisri[i]为从i到n的lis ***********/int BS(int n,int k){int l=0,r=n-1;while(l<=r){int mid=(l+r)>>1;if(dp[mid]>=k){r=mid-1;}else {l=mid+1;}}return l;}int main(){int t,i,j,k=1,l,n;scanf("%d",&t);while(t--){scanf("%d%d",&n,&l);for(i=0;i<n;++i){scanf("%d",&num[i]);}int len=0,ans=0,pos;for(i=n-1;i>=0;--i){pos=BS(len,-num[i]);dp[pos]=-num[i];ri[i]=pos;if(pos==len)len++;}len=ans=0;memset(li,0,sizeof(li));for(i=0;i<n;++i){if(i+l<n){pos=BS(len,num[i+l]);li[i+l]=pos;}pos=BS(len,num[i]);dp[pos]=num[i];if(pos==len)len++;if(i<n-l)ans=max(ans,pos+1);}for(i=l;i<n;++i){ans=max(ans,ri[i]+li[i]+1);}printf("Case #%d: %d\n",k++,ans);}return 0;}
0 0
- hdoj5489Removed Interval【lis】
- HDU5489 Removed Interval LIS
- hdu5489 Removed Interval LIS
- [HDU 5489]Removed Interval[LIS]
- hdu 5489 Removed Interval LIS变形
- HDU 5489 Removed Interval (LIS,变形)
- HDU5489 Removed Interval (LIS变形)
- hdu 5489 Removed Interval lis变形
- HDU5489-Removed Interval(LIS变形)
- Hdu 5489 Removed Interval【LIS+线段树】
- hdu 5489 Removed Interval(线段树+LIS)
- hdoj 5489 Removed Interval 【线段树维护LIS or LIS变形】
- interval
- INTERVAL
- interval
- 2015合肥网络赛 HDU 5489 Removed Interval LIS+线段树(树状数组)
- LIS
- LIS
- MySQLi基于面向对象的编程
- UVA 1594
- MySQLi的高级应用
- no system images installed for target 问题的解决办法
- 函数指针 虚函数遐思
- hdoj5489Removed Interval【lis】
- UVA 10935
- neuq oj 1012 SZ斐波拉契数列 C++
- JVM类的加载过程
- UVA 10763
- ListView中getView的原理+如何在ListView中放置多个item
- opencv 膨胀(dilate)与腐蚀(erode)---基本 数学形态学
- 1017. Queueing at Bank (25)
- UVA 10391