Emuskald is a avid horticulturist and owns the world's longest greenhouse-it is effectively infinite in length.
Over the years Emuskald have cultivated n plants in he greenhouse, of m different plant species numbered from 1 to M. His greenhouse are very narrow and can be viewed as an infinite line, with each plant occupying .
Emuskald has discovered this species thrives at a different temperature, so he wants to arrange m?-? 1 borders that Wo Uld divide the greenhouse into M-sections numbered from 1-to-m from left-to-right with each section housing a single speci Es. The borders, but in the end all of the i-th species plants must reside in i-th sections from the left.
Of course, it is not always possible to place the borders in such-on, so Emuskald needs to replant some of his plants. He can remove each plant from its position and place it anywhere in the greenhouse (at any real coordinate) with no plant Already in it. Since replanting is a lot of stress for the plants, help Emuskald find the minimum number of plants he have to replant to B e able to place the borders.
Input
The first line of input contains, space-separated integers n and M (1?≤?n,?m?≤?5000, n?≥?m), the number of plants and t He number of different species. Each of the following n lines contain the space-separated numbers:one integer number si (1?≤?si?≤?m), and one real number XI (0?≤?xi?≤?109), the species and position of the i-th plant. Each XI would contain no more than 6 digits after the decimal point.
It is guaranteed, all Xi is different; There is at least one plant for each species; The plants is given in order ' from left to the right ', that's in the ascending order of their XI coordinates (XI?<?XI ? +?1,?1?≤?i?<?n).
Output
Output a single integer-the minimum number of plants to be replanted.
Sample Test (s)
Input
3 2
2 1
1 2.0
1 3.100
Output
1
Input
3 3
1 5.0
2 5.5
3 6.0
Output
0
Input
6 3
1 14.284235
2 17.921382
1 20.328172
3 20.842331
1 25.790145
1 27.204125
Output
2
Note
In the first test case, Emuskald can replant the first plant to the right of the last plant, so the answer is 1.
The second test case, the species was already in the correct order, so no replanting is needed.
is to seek LIS, the answer is N-lis, that is, to re-grow the
/************************************************************************* > File name:cf-165-d.cpp > Aut Hor:alex > Mail: [email protected] > Created time:2015 March 28 Saturday 12:36 28 seconds ******************************* *****************************************/#include <map>#include <set>#include <queue>#include <stack>#include <vector>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace STD;Const DoublePI =ACOs(-1.0);Const intINF =0x3f3f3f3f;Const DoubleEPS =1e-15;typedef Long LongLL;typedefPair <int,int> PLL;Const intN =5050;intpos[5050];intdp[5050];intMain () {intN, M; while(~scanf("%d%d", &n, &m)) {DoubleX for(inti =1; I <= N; ++i) {scanf("%D%LF", &pos[i], &x); Dp[i] =1; }intAns =1; for(inti =1; I <= N; ++i) { for(intj =1; J < I; ++J) {if(Pos[i] >= pos[j] && dp[i] < Dp[j] +1) {Dp[i] = Dp[j] +1; }} ans = max (ans, dp[i]); }printf("%d\n", N-ans); }return 0;}
Codeforces Round #165 (Div. 2)---D. Greenhouse Effect