Rectangles(搜索)

描述

A rectangle in the Cartesian plane is specified 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.

输入

The 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.

输出

For each input test case, print a single integer indicating the length of the longest chain.

样例输入

3
1 5 2 8
3 -1 5 4
10 10 20 20
2
2 1 4 5
6 5 8 10
0

样例输出

2
1
题意:
给你n个矩形的左下角坐标和右下角坐标,问你这些矩形能排队的最大个数是多少?
排队的条件是后一个矩形的左下角得在前一个矩形右上角的右上方,也就是前.x2<后.x1&&前.y2<后.y1

#include <bits/stdc++.h>
using namespace std;
struct pe{
    int x1,y1,x2,y2;
}p[1005];
int t;
int ma;
int dp[1005];
int f(int id){
    if(dp[id]) return dp[id];
    for(int i=0;i<t;i++){
        if(p[id].x2<p[i].x1&&p[id].y2<p[i].y1){
            dp[id]= max(dp[id],f(i)+1);
        }
    }
    return max(dp[id],1);
}
int main(){
    while(scanf("%d",&t),t){
        ma=1;
        memset(dp,0,sizeof(dp));
        int x1,y1,x2,y2;
        for(int i=0;i<t;i++){
        	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        	p[i]={x1,y1,x2,y2};
        }
        for(int i=0;i<t;i++){
            ma=max(f(i),ma);
        }
        printf("%d\n",ma);
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值