From 787d25df069840b9d0f245dd0877ec5f0af00aa2 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 3 Apr 2022 21:49:32 +0800 Subject: [PATCH] =?UTF-8?q?1290.=20=E9=87=87=E8=8D=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit http://ybt.ssoier.cn:8088/statusx.php?runidx=15594277 --- ybt/1290/1290.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 ybt/1290/1290.cpp diff --git a/ybt/1290/1290.cpp b/ybt/1290/1290.cpp new file mode 100644 index 00000000..d3ff3a59 --- /dev/null +++ b/ybt/1290/1290.cpp @@ -0,0 +1,28 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1005; + +int m, n, w[N], v[N], f[N]; + +int main() { + std::ios::sync_with_stdio(false); + + cin >> m >> n; + for (int i = 1; i <= n; i++) { + cin >> w[i] >> v[i]; + } + + for (int i = 1; i <= n; i++) { + for (int j = m; j; j--) { + f[j] = std::max(f[j], j >= w[i] ? f[j - w[i]] + v[i] : f[j]); + } + } + + cout << f[m] << endl; + + return 0; +}