0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 19:08:47 +00:00

P1441 砝码称重

https://www.luogu.com.cn/record/78343607
This commit is contained in:
Baoshuo Ren 2022-07-03 16:38:32 +08:00
parent 85a040f217
commit 614a605e81
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

40
Luogu/P1441/P1441.cpp Normal file
View File

@ -0,0 +1,40 @@
#include <iostream>
#include <bitset>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 20;
int n, m, a[N], ans;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < 1 << n; i++) {
if (__builtin_popcount(i) == n - m) {
std::bitset<2005> s;
s[0] = 1;
for (int j = 0; j < n; j++) {
if (i & (1 << j)) {
s |= s << a[j];
}
}
ans = std::max(ans, (int)s.count());
}
}
cout << ans - 1 << endl;
return 0;
}