From dd08012a6c64464003b4223ccd1bf2a6375a9627 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Tue, 15 Nov 2022 20:46:48 +0800 Subject: [PATCH] =?UTF-8?q?P4138=20[JOISC2014]=20=E6=8C=82=E9=A5=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/94138309 --- Luogu/P4138/P4138.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Luogu/P4138/P4138.cpp diff --git a/Luogu/P4138/P4138.cpp b/Luogu/P4138/P4138.cpp new file mode 100644 index 00000000..536ae132 --- /dev/null +++ b/Luogu/P4138/P4138.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 2005; + +int n, f[N][N], ans; +std::pair 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; +}