mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-08 15:18:46 +00:00
1267. 【例9.11】01背包问题
http://ybt.ssoier.cn:8088/statusx.php?runidx=15592920
This commit is contained in:
parent
c0d0f81ff3
commit
c7b42548d4
28
ybt/1267/1267.cpp
Normal file
28
ybt/1267/1267.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include <iostream>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 205;
|
||||
|
||||
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 = m; j; j--) {
|
||||
f[i][j] = std::max(f[i - 1][j], j - w[i] >= 0 ? f[i - 1][j - w[i]] + c[i] : -1);
|
||||
}
|
||||
}
|
||||
|
||||
cout << f[n][m] << endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user