Topic Links:
Codeforces
Main topic:
Give a real axis, which is scattered n points, they are m species, ask at least how many steps can be divided into the number of points on the axis of the 1~m order of the kind of M block.
Topic Analysis:
- First we can know that there must be a strategy to place a point once to where it should be placed.
- So for the plants we want to move, we have to move at most for each plant, defining state dp[i] to represent the first I plant, to ensure that the maximum number of plants to keep in ascending order.
- The transfer equation is obvious, d P[I]=max{d P[J]}+1,s[I]>= s[J]
- We add a plant of type m+1 at the end of the sequence so that the last plant we retain is dp[n], and then the moving plant only needs to be moved once, so N-dp[n] is the final answer.
AC Code:
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#define MAX 5007using namespace STD;intN,m,s[max],dp[max];DoubleXintMain () { while( ~scanf("%d%d", &n, &m)) { for(inti =1; I <= N; i++)scanf("%d%lf", &s[i], &x); S[++n] = m+1; for(inti =1; I <= N; i++) {Dp[i] =0; for(intj =1; J < I; J + +)if(S[i] >= s[j]) dp[i] = max (Dp[i], dp[j]); dp[i]++; }printf("%d\n", N-dp[n]); }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Codeforces 269B B. Greenhouse Effect (DP)