mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 15:16:28 +00:00
CF294B Shaass and Bookshelf
R73175686
This commit is contained in:
parent
548a8a0683
commit
455f0aa2ca
39
Luogu/CF294B/CF294B.cpp
Normal file
39
Luogu/CF294B/CF294B.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 105;
|
||||
|
||||
int n, v[N], w[N], f[N * N], sum, ans;
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> v[i] >> w[i];
|
||||
sum += v[i];
|
||||
}
|
||||
|
||||
memset(f, 0x3f, sizeof(f));
|
||||
f[0] = 0;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = sum; j >= v[i]; j--) {
|
||||
f[j] = std::min(f[j], f[j - v[i]] + w[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = sum; i >= 0; i--) {
|
||||
if (f[i] <= sum - i) {
|
||||
ans = sum - i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cout << ans << endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user