poj1065(单调递增最长子序列变形)

题目链接:poj1065 

/*
题意:有一些木棒,它们的长度(l)和质量(w)都已经知道,需要一个机器处理这些木棒,
机器开启的时候需要耗费一个单位的时间,如果第i+1个木棒的重量和长度都大于等于
第i个处理的木棒,那么将不会耗费时间,否则需要消耗一个单位的时间

思路:首先对长度和质量从大到小排序,然后找质量的单调最长子序列长度,类似hdu1257最少拦截系统
*/
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 5005;
int d[N];
struct node
{
	int l,w;
	bool operator < (const node &cmp) const{
		return l > cmp.l || l == cmp.l && w > cmp.w;//从大到小排序
	}
}s[N];
int main()
{
    int T,n,i,j;
    scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&n);
		for(i = 0; i < n; i ++)
			scanf("%d%d",&s[i].l,&s[i].w);
		sort(s,s+n);
		int top = 0;
		d[0] = -inf;
		for(i = 0; i < n; i ++){
			if(s[i].w > d[top]){
				d[++top] = s[i].w;
				continue;
			}
			int pos = lower_bound(d, d+top+1, s[i].w) - d;
			d[pos] = s[i].w;
		}
		printf("%d\n",top);
	}
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值