P1375 nested rectangle and p1375 nested rectangle

Source: Internet
Author: User

P1375 nested rectangle and p1375 nested rectangle
QuestionProblem nested rectangle Time Limit: 1000 ms Memory Limit: 131072KBDescriptionDescript.

There are n rectangles. Each rectangle can be described by a and B to indicate length and width. Rectangle X (a, B) can be nested in Rectangle Y (c, d) When and only when a <c, B <d or B <c, a <d (equivalent to rotating x 90 degrees ). For example, () can be nested in (), but cannot be nested in. Your task is to select as many rectangles as possible in a row, so that, except the last one, each rectangle can be nested in the next rectangle.

InputInput 1st rows n (n <= 2000)
Two numbers a and B in each row from 2nd to n + 1 indicate the length and width of the rectangle. OutputOutput is a single number. The maximum number of rectangles that meet the condition is ExampleSample input data
31 56 23 4
Output Data
2
RemarksHint smartoj does not have an evaluation machine... I don't know, right ,,
 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 using namespace std; 6 const int MAXN=2001; 7 void read(int & n) 8 { 9     char c='+';int x=0;bool flag=0;10     while(c<'0'||c>'9')11     {c=getchar();if(c=='-')flag=1;}12     while(c>='0'&&c<='9')13     {x=x*10+(c-48);c=getchar();}14     flag==1?n=-x:n=x;15 }16 int map[MAXN][MAXN];17 struct node18 {19     int hang;20     int lie;21     int id;22 }a[MAXN*4];23 int ans=0;24 int n;25 int dis[MAXN];26 int M_s(int p)27 {28     ans=max(ans,dis[p]);29     if(dis[p])30     return dis[p];31     for(int i=1;i<=n;i++)32     {33         if(map[p][i])34         return dis[p]=max(dis[p],M_s(i)+1);35     }36 }37 int main()38 {39     read(n);40     for(int i=1;i<=n;i++)41     {42         int x,y;43         read(x);read(y);44         a[i].hang=x;a[i].lie=y;a[i].id=i;45     }46     for(int i=1;i<=n;i++)47         for(int j=1;j<=n;j++)48             if(i!=j)49                 if((a[i].hang<a[j].hang&&a[i].lie<a[j].lie)||(a[i].lie<a[j].hang&&a[i].hang<a[j].lie))50                     map[a[i].id][a[j].id]=1;51     52     M_s(1);53     int out=1;54     for(int i=1;i<=n;i++)55     {56         out=max(out,dis[i]+1);57     }58     printf("%d",out);59     return 0;60 }

 

 

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.