hdu 6197 array array array

http://acm.hdu.edu.cn/showproblem.php?pid=6197

题意:给你一个数组 然后给你一个k  让你从数组里面剔除k个数  使得剩余的数组 是 单调非递减  或 单调非递增的

判断可不可能

思路 : 直接写LIS  然后判断 n-k 和 LIS 长度的大小关系

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+100;
const int INF = 0x3f3f3f3f;
int n,m;
int s[maxn];
int cnt[maxn];

int main ()
{
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--){
        cin >> n >> m;
        for(int i=1;i<=n;i++)
            cin >> s[i];
        fill(cnt,cnt+n,INF);
        for(int i=1;i<=n;i++)
        {
            *upper_bound(cnt,cnt+n,s[i]) = s[i];
        }
        int len1 = lower_bound(cnt,cnt+n,INF) - cnt;
        fill(cnt,cnt+n,INF);
        for(int i=n;i>=1;i--)
        {
            *upper_bound(cnt,cnt+n,s[i]) = s[i];
        }
        int len2 = lower_bound(cnt,cnt+n,INF) - cnt;
        int ans = max(len1,len2);
        if(n-m > ans)
            puts("A is not a magic array.");
        else
            puts("A is a magic array.");
    }
}
原文地址:https://www.cnblogs.com/Draymonder/p/7502698.html