lis (not strict): first I think of the LIS, but always feel a bit wrong, each number minus its subscript, to prevent the following situation: (reprint)3 The join sequence is 1,2,2,2,3, so that the ascending sub-sequence is 3, that is, to modify 2, but the middle of two 2, the range of changes can not exceed (1,3)4 then it is wrong to ask, but after the loss, it is equivalent to the number of repetitions in the middle left the room for modification .5 explain why it can be reduced and remain correct: because the topic is strictly incremented, assuming that it is 2, 3, 4, then 1, 1, 1, so in the LIS is not strictly incremented can be6 This is why you should insert it in the Upper_bound position.7 In addition: Lower_bound returns the position of the first >=key, Upper_bound returns the position of the first >key so that subtracting is the number of keys
#include <iostream> #include <algorithm> #include <cstdio>using namespace std;const int INF = 9999990; int A[100001],dp[100001];int Main () { #ifdef xxz freopen ("In.txt", "R", stdin); #endif//xxz int n,t; scanf ("%d", &t); for (int CA = 1; CA <= T; ca++) { scanf ("%d", &n); for (int i = 0; i < n; i++) scanf ("%d", a+i), a[i]-= i; Fill (DP,DP + N, INF); for (int i = 0; i < n; i++) { *upper_bound (dp,dp+n,a[i]) = A[i]; } printf ("Case #%d:\n%d\n", Ca,n-(Lower_bound (Dp,dp+n,inf)-DP)); } return 0;}
201,500-degree star Preliminaries 2 1005 sequence Transformation (LIS variant)