HDU5489-Removed Interval(LIS变形)
来源:互联网 发布:java的编程思想是什么 编辑:程序博客网 时间:2024/06/05 06:09
Removed Interval
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1667 Accepted Submission(s): 545
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
Source
2015 ACM/ICPC Asia Regional Hefei Online
Recommend
wange2014
解题思路:对于【L,n-1】里的数可以先处理出以a【i】为头的后面的LIS(可以从后往前处理)。对于某一位,可以假设出现在最终的序列中,以这一位为头的LIS已经处理好,然后还可以算出以这个数结尾,去掉前L个的LIS(类似于O(nlogn)计算LIS),看它在前面的LIS的哪里,两者相加-1就可以算出最终的LIS
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <map>#include <cmath>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>#include <functional>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;int a[100005], x[100005], b[100005], dp[100005];int main(){int t, cas=0;scanf("%d", &t);while(t--){int n, l;scanf("%d%d", &n, &l);for (int i = 0; i < n; ++i){scanf("%d", &a[i]);b[i] = -a[i];}memset(x, INF, sizeof x);for (int i = n - 1; i >= l; --i){int k = lower_bound(x, x + n, b[i]) - x;x[k] = b[i];dp[i] = k + 1;}int ans = 0, mxlen = 0;memset(x, INF, sizeof x);for (int i = l; i < n; ++i){int k = lower_bound(x, x + n, a[i]) - x;ans = max(ans, k + 1 + dp[i] - 1);k = lower_bound(x, x + n, a[i - l]) - x;x[k] = a[i - l];mxlen = max(mxlen, k + 1);}ans = max(ans, mxlen);printf("Case #%d: %d\n",++cas,ans);}return 0;}
0 0
- HDU5489 Removed Interval (LIS变形)
- HDU5489-Removed Interval(LIS变形)
- HDU5489 Removed Interval LIS
- hdu5489 Removed Interval LIS
- HDU 5489 Removed Interval (LIS,变形)
- hdu5489 Removed Interval(dp+线段树)
- hdu5489 Removed Interval
- hdu5489 Removed Interval
- hdu5489 Removed Interval
- hdu 5489 Removed Interval LIS变形
- hdu 5489 Removed Interval lis变形
- hdoj 5489 Removed Interval 【线段树维护LIS or LIS变形】
- [HDU 5489]Removed Interval[LIS]
- hdu 5489 Removed Interval(线段树+LIS)
- Hdu 5489 Removed Interval【LIS+线段树】
- HDU 5489 Removed Interval(DP)
- 2015合肥网络赛 HDU 5489 Removed Interval LIS+线段树(树状数组)
- hdu 5489 Removed Interval
- 整数拆段(枚举,DP)(AOJ 847)
- 1051 最大子矩阵和
- 第十一周
- L1-003. 个位数统计
- Effective OC之熟悉Objective-C
- HDU5489-Removed Interval(LIS变形)
- C++作业6
- 写给自己的寄语
- 浮点数注意事项
- tomcat 开启nio
- 初识StringBuffer类
- Vampire Numbers
- 设计模式拾荒之责任链模式 ( Chain of Responsibility)
- 搭建完全分布式Hadoop