From 89352b82f6aa209f3950dda68b4c756c2e6b84ab Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Wed, 4 Nov 2020 09:28:22 +0800 Subject: [PATCH] =?UTF-8?q?P1507=20NASA=E7=9A=84=E9=A3=9F=E7=89=A9?= =?UTF-8?q?=E8=AE=A1=E5=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R41202952 --- problem/P1507/P1507.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 problem/P1507/P1507.cpp diff --git a/problem/P1507/P1507.cpp b/problem/P1507/P1507.cpp new file mode 100644 index 00000000..11051c1c --- /dev/null +++ b/problem/P1507/P1507.cpp @@ -0,0 +1,24 @@ +#include + +using namespace std; + +int n, u, v, w[505], z[505], c[505], f[55][505][505]; + +int main() { + cin >> u >> v >> n; + for (int i = 1; i <= n; i++) { + cin >> w[i] >> z[i] >> c[i]; + } + for (int i = 1; i <= n; i++) { + for (int j = u; j > 0; j--) { + for (int k = v; k > 0; k--) { + f[i][j][k] = f[i - 1][j][k]; + if (j >= w[i] && k >= z[i]) { + f[i][j][k] = max(f[i][j][k], f[i - 1][j - w[i]][k - z[i]] + c[i]); + } + } + } + } + cout << f[n][u][v] << endl; + return 0; +}