Test instructions: An LIS that deletes L continuous elements in a sequence.
Solution: My idea is very complex = = How to say it ... First, using the Nlogn method to obtain the sequence of the LIS series DP of the meaning of the ascending sub-sequence of all the length of the end of the sequence of elements of the minimum value, then the first backward with the Nlogn method of the longest descending sub-sequence is recorded as DP1, record each step how to update the DP1, and then to find the longest ascending subsequence , each time you look at A[i], the second point in the i+k to the end of the DP1 to find the first than the a[i] large number is set to Dp1[pos], so the answer of the current enumeration is the longest ascending sub-sequence with a[i] as the end of the last paragraph with the beginning of Dp1[pos] the longest ascending subsequence ... Enumerate 1~n-l, you can get the answer tut ...
It's hard ... Two points of waste and have to find teammates help handwritten two points what ...
Another team of people proposed to use line tree to calculate lis ... True • Great god = = Do not know how to transfer the equation ...
Code:
#include <stdio.h> #include <iostream> #include <algorithm> #include <string> #include < string.h> #include <math.h> #include <limits.h> #include <time.h> #include <stdlib.h># include<map> #include <queue> #include <set> #include <stack> #include <vector> #define LL Long Longint inf = 1000000005;using namespace Std;int a[100005]; LL dp1[100005], dp2[100005];struct node{bool isnew; int POS; int pre;} Note[100005];bool CMP (int a, int b) {return a > B;} Template <class t>int rupper_bound (t *a, T *end, t key) {int n = end-a; if (n = = 0) return int_max; if (A[n-1] > key) return n-1; if (A[0] <= key) return Int_max; int L = 0, r = n-1; while (R-l > 1) {int m = (l+r) >> 1; if (A[m] > key) L = m; else r = m; } return L;} int main () {int T; scanf ("%d", &t); int CSE = 1; while (t--) {int n, l; scanf ("%d%d", &n, &l); for (int i = 1; I <= n; i++) scanf ("%d", &a[i]); A[0] =-inf; int max1 = 0, max2 = 0; for (int i = n; i > L; i--) {int pos = Upper_bound (DP1, DP1 + max1, A[i], CMP)-DP1; if (pos = = max1) {note[i].isnew = 1; Note[i].pos = Max1; dp1[max1++] = A[i]; } else {note[i].isnew = 0; Note[i].pos = pos; Note[i].pre = Dp1[pos]; Dp1[pos] = A[i]; }} int ans = 0; LL s =-inf; int len = 0; for (int i = 1; I <= n-l + 1; i++) {int pos = Rupper_bound (DP1, DP1 + max1, s); if (pos = = int_max) ans = MAX (ans, Len); else ans = max (ans, pos + 1 + len); int x = Upper_bound (DP2, DP2 + max2, A[i])-DP2; if (x = = max2) {len = max2 + 1;s = a[i]; dp2[max2++] = A[i]; } else {len = x + 1; s = a[i]; DP2[X] = A[i]; } if (Note[i + l].isnew) {max1--; } else {dp1[note[i + L].pos] = note[i + l].pre; }} printf ("Case #%d:%d\n", cse++, ans); } return 0;}
HDU 5489 removed Interval