CF269B Greenhouse Effect (dp LIS)

Topic scary series, this string of floating-point position to see me cry, then carefully read the questions, identify problems to ask is, how many times at least after the non-aligned movement can strictly monotonically increasing sequence

Why is it, because he wanted the m sub-region, and requires that each species are located i i area, you can only put all the non-aligned strictly increasing job

That this question is simple, in fact, seeking LIS, followed by reducing the total number on the line, I use here is the stack simulation nlogn, do not know can not be too n ^ 2

#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#include<set>
#define ull unsigned long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int N=1e5+10;
int f[5010][5010];
int a[N];
vector<int> num;
int main(){
    int n;
    int m;
    int i;
    cin>>n>>m;
    for(i=1;i<=n;i++){
        double x;
        scanf("%d%lf",&a[i],&x);
    }
    num.clear();
    num.push_back(a[1]);
    for(i=2;i<=n;i++){
        if(a[i]>=num.back())
            num.push_back(a[i]);
        else{
            int pos=upper_bound(num.begin(),num.end(),a[i])-num.begin();
            num[pos]=a[i];
        }
    }
    int ans=n-(int)num.size();
    cout<<ans<<endl;
    return 0;
}
View Code

 

Guess you like

Origin www.cnblogs.com/ctyakwf/p/12637480.html