[CF269B] Greenhouse Effect - dp

Gives the N plants, each plant belongs to a species, a total of m species, different points fall position (a number line, and the length of the unlimited number of axes), to ensure that the position of the read is to read in ascending order of the of.

Now we can perform an operation: take any plant, moved to an arbitrary position on a plant without a seat up.

We asked how many operations for a minimum, can be made from left to right, in accordance with the ascending order of the species (1 ~ m) (monotone not fall), and are adjacent to each plant.

Solution

Ask about the longest non-strict sequence to rise

#include <bits/stdc++.h>
using namespace std;

int n,m,a[5005],f[5005];
double t;

int main() {
    cin>>n>>m;
    for(int i=1;i<=n;i++) {
        cin>>a[i]>>t;
    }
    int ans=0;
    for(int i=1;i<=n;i++) {
        f[i]=1;
        for(int j=1;j<i;j++) {
            if(a[j]<=a[i]) f[i]=max(f[i], f[j]+1);
        }
        ans=max(ans,f[i]);
    }
    cout<<n-ans;
}

Guess you like

Origin www.cnblogs.com/mollnn/p/12275483.html