From a1193e508aa475b57a8cfe163930d4ae28c14794 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 3 Apr 2022 21:21:18 +0800 Subject: [PATCH] =?UTF-8?q?1268.=20=E3=80=90=E4=BE=8B9.12=E3=80=91?= =?UTF-8?q?=E5=AE=8C=E5=85=A8=E8=83=8C=E5=8C=85=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit http://ybt.ssoier.cn:8088/statusx.php?runidx=15593781 --- ybt/1268/1268.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 ybt/1268/1268.cpp diff --git a/ybt/1268/1268.cpp b/ybt/1268/1268.cpp new file mode 100644 index 00000000..94735d39 --- /dev/null +++ b/ybt/1268/1268.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], c[N], f[N][N]; + +int main() { + std::ios::sync_with_stdio(false); + + cin >> m >> n; + for (int i = 1; i <= n; i++) { + cin >> w[i] >> c[i]; + } + + for (int i = 1; i <= n; i++) { + for (int j = 0; j <= m; j++) { + f[i][j] = std::max(f[i - 1][j], j >= w[i] ? f[i][j - w[i]] + c[i] : f[i - 1][j]); + } + } + + cout << "max=" << f[n][m] << endl; + + return 0; +}