POJ 3636 Nested Dolls -(最长上升子序列)

题目链接:http://poj.org/problem?id=3636
最小链划分数 = 最长反链长度
按如下关系排序:
w 1 > w 2 ∨ ( w 1 = w 2 ∧ h 1 ≤ h 2 ) w_1 \gt w_2 \lor (w_1 = w_2 \land h_1 \le h_2) w1>w2(w1=w2h1h2)
定义反链:
w 1 ≥ w 2 ∧ h 1 ≤ h 2 w_1 \ge w_2 \land h1 \le h_2 w1w2h1h2

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

inline int read_int() { int a; scanf("%d", &a); return a; }
inline void outdn(int x) { printf("%d\n", x); }

struct doll_t {
    int w, h;
};

struct comp_t {
    bool operator()(doll_t d1, doll_t d2) const {
        if (d1.w > d2.w) return true;
        if (d1.w < d2.w) return false;
        return d1.h < d2.h;
    }
};


int main() {
    int T = read_int();
    comp_t comp;
    while (T--) {
        const int m = read_int();
        vector<doll_t> dolls(m);
        for (int i = 0; i < m; i++) {
            dolls[i].w = read_int();
            dolls[i].h = read_int();
        }
        sort(dolls.begin(), dolls.end(), comp);
        vector<int> seq(m, 0x7fffffff);
        for (int i = 0; i < m; i++)
            *upper_bound(seq.begin(), seq.end(), dolls[i].h) = dolls[i].h;
        outdn(lower_bound(seq.begin(), seq.end(), 0x7fffffff) - seq.begin());
    }
    //system("pause");
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值