제출 #1327854

#제출 시각아이디문제언어결과실행 시간메모리
1327854tkm_algorithmsLet's Win the Election (JOI22_ho_t3)C++20
0 / 100
2635 ms982656 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
//#define int ll
using P = pair<int, int>;
#define all(x) x.begin(), x.end()
#define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e)?x++:x--))
#define sz(x) (int)x.size()
const char nl = '\n';
const int mod = 998244353;

bool cmp(P a, P b) {
	if (a.second != -1 && b.second != -1)return a.second < b.second;
	else if (a.second != -1)return 1;
	else if (b.second != -1)return 0;
	return a.first < b.first;
}

void mnu(double &x, double y) {
	if (y == -1)return;
	if (x ==-1 || y < x)x = y;
}

void solve() {
	int n, k; cin >> n >> k;
	vector<P> a(n);
	for (auto &i: a)cin >> i.first >> i.second;
	
	sort(all(a), cmp);
	
	//for (auto i: a)cout << i.first << ' ' << i.second << nl;
	
	double dp[n][n+1][n+1];
	rep(i, 0, n)	
		rep(j, 0, n+1)
			rep(p, 0, n+1)dp[i][j][p] = -1;
		
	rep(i, 0, n) {
		dp[i][1][0] = a[i].first;
		if (a[i].second != -1)dp[i][1][1] = a[i].second;
		dp[i][0][0] = 0;
	}
	
	rep(i, 0, n) {
		rep(j, 1, i+2)
			rep(cnt, 0, i+2) {
				if (i)mnu(dp[i][j][cnt], dp[i-1][j][cnt]);
				//if (i == n-1 && j == 3)cout << dp[i-1][j-1][cnt]+a[i].first <<nl;
				for (int x = i-1; x >= 0; --x) { // bring i-th
					//if (i == n-1 && j == 3) {
						//cout << a[i].first<< nl;
					//}
					if (dp[x][j-1][cnt]== -1)continue;
					mnu(dp[i][j][cnt], dp[x][j-1][cnt]+(double)a[i].first/(double)(cnt+1));
					if (cnt && a[i].second > 0) // bring i-th and it'll be col;
						mnu(dp[i][j][cnt], dp[x][j-1][cnt-1]+(double)a[i].second/(double)(cnt));
				}
			}
	}
	
	double res = -1;
	//cout << dp[0][k-1][0] << nl;
	rep(cnt, 0, k+1)mnu(res, dp[n-1][k][cnt]);
	cout << res << nl;
	//cout << setprecision(10) << fixed << res << nl;
	//for (auto i: a)cout << i.first << " " << i.second << nl;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...