bzoj2298 Problem a

  Problem a

题目背景:

bzoj2298

分析:DP

 

额,属于我是真的没有想到这样的状态转移啊······一脸懵逼·····显然一个人在自己前面的有a个,后面有b个,那么这个人的排名区间为[a + 1, n - b]并且,这个区间中所有人的成绩应该相同,定义f[i]表示,排名第i的人的分数不等于第i + 1的分数,那么转移就是f[i] = max(f[i - 1], f[j] + min(i - j, num)) (num表示排名区间为[j + 1, i]的人数)

Source

/*
	created by scarlyw
*/
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
#include <cctype>
#include <vector>
#include <set>
#include <queue>

const int MAXN = 100000 + 10;

struct data {
	int l, r;
	data(int l = 0, int r = 0) : l(l), r(r) {}
	inline bool operator < (const data &a) const {
		return (r == a.r) ? (l < a.l) : (r < a.r);
	}
} p[MAXN];

int n, x, y, cnt;
int f[MAXN];
inline void solve() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d%d", &x, &y);
		if (x + y < n) p[++cnt] = data(x + 1, n - y);
	}
	std::sort(p + 1, p + cnt + 1);
	for (int i = 1, head = 1; i <= n; ++i) {
		f[i] = f[i - 1];
		int temp = 0;
		while (head <= n && p[head].r == i) { 
			if (p[head].l == p[head - 1].l) temp++;
			else temp = 1;
			f[i] = std::max(f[i], f[p[head].l - 1] + 
				std::min(temp, i - p[head].l + 1)), head++;
		} 
	}
	printf("%d", n - f[n]);
}

int main() {
	solve();
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值