HDU--3457 -- Rectangles -- memory-based search

Source: Internet
Author: User

HDU--3457 -- Rectangles -- memory-based search

RectanglesTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 707    Accepted Submission(s): 284Problem DescriptionA rectangle in the Cartesian plane is speci ed by a pair of coordinates (x1 , y1) and (x2 , y2) indicating its lower-left and upper-right corners, respectively (where x1 ≤ x2 and y1 ≤ y2). Given a pair of rectangles,A = ((xA1 , yA1 ), (xA2 ,yA2 )) and B = ((xB1 , yB1 ), (xB2 , yB2 )), we write A ≤ B (i.e., A "precedes" B), if xA2 < xB1 and yA2 < yB1 :In this problem, you are given a collection of rectangles located in the two-dimension Euclidean plane. Find the length L of the longest sequence of rectangles (A1,A2,…,AL) from this collection such that A1 ≤ A2 ≤ … ≤ AL. InputThe input fi le will contain multiple test cases. Each test case will begin with a line containing a single integer n (where 1 ≤ n ≤ 1000), indicating the number of input rectangles. The next n lines each contain four integers xi1 ,yi1 ,xi2 ,yi2 (where -1000000 ≤ xi1 ≤ xi2 ≤ 1000000, -1000000 ≤ yi1 ≤ yi2 ≤ 1000000, and 1 ≤ i ≤ n), indicating the lower left and upper right corners of a rectangle. The end-of-file is denoted by asingle line containing the integer 0. OutputFor each input test case, print a single integer indicating the length of the longest chain. Sample Input
31 5 2 83 -1 5 410 10 20 2022 1 4 56 5 8 100

Sample Output
21


Give you the coordinates of N rectangles in the lower left corner and in the upper right corner, and then find a sequence so that each of them meets one condition with the last one, the condition is that the X and Y coordinates of the vertices in the upper-right corner of the previous item are smaller than those in the lower-left corner of the next item. There may be multiple such sequences, find the length of the longest one (the last one does not have the last one, you know, he is the biggest one)

Analysis: the memory-based search is used to reduce the time required for repeated searches. Many people who have made a lot of memory-based search questions are very quick.


# Include
  
   
# Include
   
    
# Include
    
     
# Include # define Max (a, B) a> B? A: busing namespace std; int n; int dp [1111], map [1111] [1111]; struct node {int x1, x2, y1, y2 ;} s [1111]; int dfs (int x) {int I, j, k, l; if (dp [x]) return dp [x]; // you do not need to search for (I = 0; I
     
    
   
  

Conclusion: record the optimal status. You can directly call this status when you find it here.



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.