比赛 2022级DP专题练习赛3 评测结果 TTAAATTATTTTTTATATTT
题目名称 拦截导弹 最终得分 30
用户昵称 zxhhh 运行时间 21.010 s
代码语言 C++ 内存使用 6.32 MiB
提交时间 2023-02-17 19:43:01
显示代码纯文本
#include <bits/stdc++.h>

using namespace std;

const int N = 50005;
typedef long long ll;

int n, h[N], v[N];
ll cnt[N], dp[N], s, m, t[N];
vector <int> g[N];

int main () {
	freopen("sdoi2011_daodan.in", "r", stdin);
	freopen("sdoi2011_daodan.out", "w", stdout);
	cin >> n;
	for (int i = 1;i <= n;i++) cin >> h[i] >> v[i];
	for (int i = 1;i <= n;i++) {
		int c = 0;
		for (int j = 1;j < i;j++) {
			if (h[j] >= h[i] && v[j] >= v[i]) {
				if (dp[j] > c) c = dp[j], cnt[i] = cnt[j], g[i].clear(), g[i].push_back(j);
				else if (dp[j] == c) cnt[i] += cnt[j], g[i].push_back(j);
			}
		}
		dp[i] = c + 1; m = max(m, dp[i]);
		if (!cnt[i]) cnt[i] = 1;
	}
	for (int i = 1;i <= n;i++) {
//		cout << cnt[i] << endl;
		if (m > dp[i]) continue;
		s += cnt[i];
		queue <int> q; q.push(i);
		while (q.size()) {
			int x = q.front(); q.pop();
			t[x] += cnt[x];
			for (int j = 0;j < g[x].size();j++) {
				int y = g[x][j];
				q.push(y);
			}
		}
	}
//	cout << s << endl;
	cout << m << endl;
	for (int i = 1;i <= n;i++) printf("%.5lf ", 1.0 * t[i] / s);
	return 0;
}