21773 Problem A 矩形嵌套

389 篇文章 1 订阅
144 篇文章 2 订阅

问题 A: 矩形嵌套
时间限制: 1 Sec 内存限制: 64 MB
献花: 20 解决: 17
[献花][花圈][TK题库]
题目描述
有n个矩形,每个矩形可以用a,b来描述,表示长和宽。矩形X(a,b)可以嵌套在矩形Y(c,d)中当且仅当a

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cstring>

typedef struct Rectanle
{
    int w;
    int l;
}Rect;
using namespace std;
const int MaxN = 1010;

bool cmp(Rect a, Rect b)
{
    return a.l < b.l;
}

int main()
{
#ifdef _DEBUG
    freopen("data.txt", "r+", stdin);
#endif // _DEBUG

    std::ios::sync_with_stdio(false);

    Rect rect[MaxN];
    int dp[MaxN];
    int n, m;
    cin >> n;

    while (n--)
    {
        cin >> m; dp[0] = 1;
        for (int i = 0; i < m; ++i)
        {
            int w, l;
            cin >> l >> w;
            if (l < w)
                swap(l, w);
            rect[i].l = l;
            rect[i].w = w;
        }

        sort(rect, rect + m, cmp);

        int res = 1;
        for (int i = 1; i < m; ++i)
        {
            dp[i] = 1;
            for (int k = 0; k < i; ++k)
            {
                if (rect[i].w > rect[k].w && rect[i].l > rect[k].l && dp[i] <= dp[k])
                    dp[i] = dp[k] + 1;
            }
            if (dp[i] > res)
                res = dp[i];
        }

        cout << res << endl;
    }



    return 0;
}
/**************************************************************
    Problem: 21773
    User: Sharwen
    Language: C++
    Result: 升仙
    Time:0 ms
    Memory:1700 kb
****************************************************************/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值