HDU 5489 removed Interval (LIS variant)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5489

Give you the number of n, to delete the consecutive L, ask you to delete after the maximum number of LIS?

We first preprocess the LIS, which begins with the I subscript, into the array.

You can then enumerate the ranges that are long as l, each time you move, add one to the left, and delete one on the right.

Longest ascending subsequence length = the longest ascending subsequence of the window to the right of the first element to the right and the longest ascending sub-sequence of the left side of the window that is smaller than the window to the right of the first element.

For example 1 2 [4 3] 2 3 5, LIS = 3 + 1 = 4

The LIS that begins with I, as long as the longest descending subsequence or inverted a[i] becomes negative, the longest ascending subsequence can be obtained.

The code is a bit messy.

1 //#pragma COMMENT (linker, "/stack:102400000, 102400000")2#include <algorithm>3#include <iostream>4#include <cstdlib>5#include <cstring>6#include <cstdio>7#include <vector>8#include <cmath>9#include <ctime>Ten#include <list> One#include <Set> A#include <map> - using namespacestd; -typedefLong LongLL; thetypedef pair <int,int>P; - Const intN = 1e5 +5; - intDp1[n], Dp2[n], a[n], inf = 1e9 +7; - intY[n], x[n];//Y[i] indicates that lis,x[i, which begins with the I subscript), represents the LIS ending with I +  - intMain () + { A     intt, N, M; atscanf"%d", &t); -      for(intCA =1; CA <= T; ++CA) { -scanf"%d%d", &n, &m); -          for(inti =1; I <= N; ++i) { -scanf"%d", A +i); -Dp1[i] = Dp2[i] =inf; in         } -dp2[0] = dp1[0] =inf; to         intAns =0;  +          for(inti = n; I >=1; -I.) {//The lis that begins with I, seeking to change negative -             intpos = Lower_bound (DP2, DP2 + N,-a[i])-DP2; theY[i] = pos +1; *             //cout << y[i] << Endl; $Dp2[pos] =-A[i];Panax Notoginseng             if(i = = m +1) { -Ans = lower_bound (DP2, DP2 + N, INF)-DP2; the             } +         } A         //cout << ans << endl; the          for(inti =1; I <= N; ++i) { +             intpos = Lower_bound (DP1, DP1 + N, a[i])-DP1; -X[i] = pos +1; $Dp1[pos] =A[i]; $             if(i = = N-m) { -Ans = max (int(Lower_bound (DP1, DP1 + N, INF)-dp1), ans); -                  Break; the             } -         }Wuyi         //cout << ans << endl; theprintf"Case #%d:", CA); -dp1[0] =inf; Wu          for(inti =1; I <= N; ++i) { -Dp1[i] =inf; About         } $          for(inti = m +1; I <= N; ++i) { -             intpos = Lower_bound (DP1, DP1 + N, a[i]-1)-DP1;//the left side of the sliding window is just less than the first number of LIS on the right. -ans = max (ans, y[i] + (A[i]-1= = A[pos]? POS +1: POS)); -*lower_bound (DP1, DP1 + N, a[i-m]) = A[i-m]; A         } +printf"%d\n", ans); the     } -     return 0; $}

HDU 5489 removed Interval (LIS variant)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.