Codeforces 4D

#include<iostream>
#include<cstdio>
#include<string.h>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<vector>
using namespace std;

const int maxn = 5050;
class ev{
	public:
		int w, h, idx;
		bool operator < (const ev& e) const {
			if(w == e.w){
				return h < e.h;
			}
			return w < e.w;
		}
};
ev eev[maxn];
int dp[maxn];
int pprev[maxn];
int main(){
	int n, w, h;
	while(scanf("%d%d%d",&n,&w,&h)!=EOF){
		memset(eev, 0, sizeof(eev));
		memset(dp, 0, sizeof(dp));
		memset(pprev, -1, sizeof(pprev));
		int tmpw, tmph,idx = 0,cntev;
		for(int i = 0; i < n; ++i){
			cin >> tmpw >> tmph;
			if(w >= tmpw || h >= tmph){
				continue;
			}
			eev[idx].w = tmpw;
			eev[idx].h = tmph;
			eev[idx].idx = i;
			idx++;
		}
		if(idx == 0){
			cout << "0" << endl;
			return 0;
		}
		cntev = idx;
		sort(eev, eev + idx);
		dp[0] = 1;
		pprev[0] = -1;
		for(int i = 1; i < idx; ++i){
			dp[i] = 1;
			for(int j = 0; j < i; ++j){
				if(eev[j].w < eev[i].w && eev[j].h < eev[i].h && (dp[j] + 1) > dp[i]){
					dp[i] = dp[j] + 1;
					pprev[i] = j;
				}
			}
		}
		int recmax = -1, tmpmax = -1;
		for(int i = 0; i < idx; ++i){
			if(dp[i] > tmpmax){
				tmpmax = dp[i];
				recmax = i;
			}
		}
		cout << tmpmax << endl;
		bool first = false;
		vector<int> vecint;
		for(int ttmp = recmax; ttmp != -1; ttmp = pprev[ttmp]){
			vecint.push_back(eev[ttmp].idx);
		}
		int vvecsize = vecint.size();
		for(int kkk = vvecsize - 1; kkk >= 1; --kkk){
			cout << vecint[kkk] + 1 << " ";
		}
		cout << vecint[0] + 1;
		cout << endl;
	}
	return 0;
}


转载于:https://my.oschina.net/u/1421373/blog/379419

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值