mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-08 13:18:46 +00:00
parent
865f73704c
commit
dd08012a6c
43
Luogu/P4138/P4138.cpp
Normal file
43
Luogu/P4138/P4138.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user