[luogu]CF4D Mysterious Present

前言

传送门 :

思路

看上去是含捆绑关系的 L I S LIS LIS,但是其实只要对一个关键排序,

然后另一个跑一遍 L I S LIS LIS即可

至于这题比较难的是输出路径

我们可以使用 p r e pre pre数组进行转移,每当其转移的时候 我们更改即可

Mycode

const int N  = 5e3+10;
struct node{
	int w,h,id;
};
vector<node> a;
bool cmp(node t1,node t2){
	return t1.w < t2.w;
	
}
int f[N],pre[N],hh;


int n,W,H;

int ans;
void print(int hh){
	if(hh == -1)
	return;
	print(pre[hh]);
	cout<<a[hh].id<<" ";
	
}
void solve()
{
	cin>>n>>W>>H;
	for(int i=1;i<=n;i++){
		int w,h;cin>>w>>h;
		if(w > W && h> H){
			a.pb({w,h,i});
		}
	}
	
	if(a.empty()){
		cout<<0<<endl;
		return;
	}
	sort(all(a),cmp);

	
	for(int i = 0; i< a.size() ;i++){
		f[i] = 1;
		pre[i] = -1;
	}
	
	int n = a.size();
	ans = 1;
	
	for(int i = 1 ;i < n ;i++ ){
		for(int j = 0;j<i;j++){
			if(a[j].w < a[i].w)	
				if(a[j].h < a[i].h)
					if(f[j]+1 > f[i]){
						f[i] = f[j]+1;
						pre[i] = j ;
				}
					
		}
		if(ans < f[i]){
			ans = f[i];
			hh = i;
		}
	}
	cout<<ans<<endl;
	print(hh);
	
	
	
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值