From 19ff441b6e2cf55207a438191bf8fe9394860bf6 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Sun, 25 Oct 2020 20:15:21 +0800 Subject: [PATCH] =?UTF-8?q?P1060=20=E5=BC=80=E5=BF=83=E7=9A=84=E9=87=91?= =?UTF-8?q?=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R40518321 --- problem/P1060/P1060.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 problem/P1060/P1060.cpp diff --git a/problem/P1060/P1060.cpp b/problem/P1060/P1060.cpp new file mode 100644 index 00000000..536e25b4 --- /dev/null +++ b/problem/P1060/P1060.cpp @@ -0,0 +1,25 @@ +#include + +using namespace std; + +int n, m, v[30005], w[30005], f[30][30005]; + +int main() { + cin >> n >> m; + for (int i = 1; i <= m; i++) { + cin >> v[i] >> w[i]; + w[i] *= v[i]; + } + for (int i = 1; i <= m; i++) { + for (int j = 0; j <= n; j++) { + if (j >= v[i]) { + f[i][j] = max(f[i - 1][j], f[i - 1][j - v[i]] + w[i]); + } + else { + f[i][j] = f[i - 1][j]; + } + } + } + cout << f[m][n] << endl; + return 0; +}