From 7cf4966438ca1bbfe65f91441b3fb7880ec3fbbc Mon Sep 17 00:00:00 2001 From: xingyou wu <3050128610@qq.com> Date: Wed, 9 Apr 2025 12:08:36 +0800 Subject: [PATCH] =?UTF-8?q?lanqiao=201174=20=E5=B0=8F=E6=98=8E=E7=9A=84?= =?UTF-8?q?=E8=83=8C=E5=8C=851(=E9=99=8D=E7=BB=B4=E4=BC=98=E5=8C=96)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 00lanqiao chap/test100-1-2.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 00lanqiao chap/test100-1-2.cpp diff --git a/00lanqiao chap/test100-1-2.cpp b/00lanqiao chap/test100-1-2.cpp new file mode 100644 index 0000000..0e74441 --- /dev/null +++ b/00lanqiao chap/test100-1-2.cpp @@ -0,0 +1,28 @@ +// lanqiao 1174 小明的背包1 +#include +using namespace std; +#define int long long +#define endl '\n' +const int N = 1e2+10, M = 1e3 + 10; +int dp[M]; +signed main() +{ + // 请在此输入您的代码 + int n, V; cin >> n >> V; + for(int i = 1; i <= n; i++){ + int w, v; cin >> w >> v; + for(int j = V; j >= w; j--){ + dp[j] = max(dp[j], dp[j-w] + v); + } + } + cout << dp[V] << endl; + return 0; +} +/* test samples -> 37 +5 20 +1 6 +2 5 +3 8 +5 15 +3 3 +*/ \ No newline at end of file