Nested rectangular DAG's dp (Deep Search + dp)

Source: Internet
Author: User

 

Rectangular nesting time limit: 3000 MS | memory limit: 65535 KB difficulty: 4
Description
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
Input
The first line is a positive number N (0 The first row of each group of test data is a positive number n, indicating the number of rectangles in the group of test data (n <= 1000)
Next n rows, each row has two numbers a and B (0 output
Each group of test data outputs one number, indicating the maximum number of rectangles that meet the conditions. Each group of output occupies one row.
Sample Input
1101 22 45 86 107 93 15 812 109 72 2
Sample output
5
Source
Typical questions
Uploaded
Zhang yuncong
This question has been around for a long time. It's quite easy to read it in the white book, but I have made a lot of mistakes and exposed all my shortcomings. It's quite good!
At the beginning, we used vector to create a map directly. We didn't see it at the beginning, and then we felt it. We changed it to an array adjacent table, which was 2688 ms, so we ran through water. Creating a map with a matrix is only 12 ms at all ...... The graph in the question is exactly a dense graph, so no matter whether it is a vector or an array, there are many times of joining the table. This is also the reason, sister! I have not encountered this problem before doing graph theory, but now I have finally met it.
#include 
   
    #include 
    
     #include #include 
     
      #include 
      
       #include 
       
        #include 
        
         #include 
         
          #include 
          
           #include
           #include 
            
             #include 
             
              #define PI acos(-1.0)#define mem(a,b) memset(a,b,sizeof(a))#define sca(a) scanf(%d,&a)#define sc(a,b) scanf(%d%d,&a,&b)#define pri(a) printf(%d,a)#define lson i<<1,l,mid#define rson i<<1|1,mid+1,r#define MM 204#define MN 1008#define INF 2000000000#define eps 1e-8using namespace std;typedef long long ll;typedef unsigned long long ULL;int n,dp[MN],head[MN*10],cnt;struct node{ int x,y;}e[MN];struct no{ int v,next;}ee[MN*10];void add(int u,int v){ ee[cnt].v=v,ee[cnt].next=head[u],head[u]=cnt++;}bool cmp(node a,node b){ if(a.x==b.x) return a.y
              
               y) swap(x,y); e[i].x=x,e[i].y=y; } sort(e+1,e+n+1,cmp); for(i=1;i<=n;i++) for(j=i+1;j<=n;j++) if(e[i].x
               
                

 

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.