HDU 1277 Nested Dolls

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.