0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-09 23:58:48 +00:00

P4138 [JOISC2014] 挂饰

https://www.luogu.com.cn/record/94138309
This commit is contained in:
Baoshuo Ren 2022-11-15 20:46:48 +08:00
parent 865f73704c
commit dd08012a6c
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

43
Luogu/P4138/P4138.cpp Normal file
View File

@ -0,0 +1,43 @@
#include <iostream>
#include <algorithm>
#include <cstring>
#include <functional>
#include <utility>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 2005;
int n, f[N][N], ans;
std::pair<int, int> a[N];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].first >> a[i].second;
}
std::sort(a + 1, a + 1 + n, std::greater<>());
memset(f, 0xc0, sizeof(f));
f[0][1] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= n; j++) {
f[i][j] = std::max(f[i - 1][j], f[i - 1][std::max(j - a[i].first, 0) + 1] + a[i].second);
}
}
for (int i = 0; i <= n; i++) {
ans = std::max(ans, f[n][i]);
}
cout << ans << endl;
return 0;
}