Files
python/GESP/CSP/P1060.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

29 lines
630 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
// 到第i个物品总价值超过j的最大收益
int dp[30][N];
int main() { // 总钱数、个数
int n, m;
// 价格、重要度
int v[30], w[30];
cin >> n >> m;
for (int i = 1; i <= m; i++)
cin >> v[i] >> w[i];
for (int i = 1; i <= m; i++) {
for (int j = 0; j <= n; j++) {
if (j < v[i]) {
// 不够钱不买
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - v[i]] + v[i] * w[i]);
}
}
}
cout << dp[m][n] << endl;
return 0;
}