Topic Links:
http://acm.hdu.edu.cn/showproblem.php?pid=1677
Test instructions
Play the Russian set of baby, ask at least a few left at last.
Exercises
This problem can be compared with the interceptor missile, because here is a two-dimensional, by the way of decreasing the H increment by W to ensure that in the saved sequence by the H ascending order, so as to lay the foundation for the two-point search.
Otherwise, if you sort in descending order of H, the saved sequence will be unordered, and the result of the dichotomy is naturally incorrect.
1#include <iostream>2#include <cstdio>3#include <algorithm>4 using namespacestd;5 6 Const intMAXN =20000+Ten;7 8 structNode {9 intW, H;Ten BOOL operator< (Constnode& tmp)Const { One returnW < Tmp.w&&h <Tmp.h; A } - }ARR[MAXN], DP[MAXN]; - the BOOLCMP (node& N1, node&n2) { - returnN1.W > N2.W | | (N1.W = = N2.W) && (n1.h<n2.h); - } - + intN; - + intMain () { A intTC; atscanf"%d", &TC); - while(tc--) { -scanf"%d", &n); - for(inti =0; I < n; i++) { -scanf"%d%d", &arr[i].w,&arr[i].h); - } inSort (arr, arr +N, CMP); - intAns =0; toDp[++ans] = arr[0]; + for(inti =1; I < n; i++) { - //DP Press W Descending, h ascending row!!! In order to maintain that the H is ascending, you must ensure that the W equals h in ascending order instead of descending the intLow =0, hig =ans; * while(Low +1<hig) { $ intMID = low + (Hig-low)/2;Panax Notoginseng if(Arr[i] < Dp[mid]) Hig =mid; - ElseLow =mid; the } + if(Arr[i] <Dp[hig]) { ADp[hig] =Arr[i]; the } + Else { -Dp[++ans] =Arr[i]; $ } $ } -printf"%d\n", ans); - } the return 0; - }
HDU 1277 Nested Dolls