201,500-degree star Preliminaries 2 1005 sequence Transformation (LIS variant)

Source: Internet
Author: User

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)

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.