题目链接:传送门
只是询问一个可行性
那么二进制拆分加一个bitset就行了
#include <bits/stdc++.h>
#define
using namespace std;
typedef long long ll;
int n, m, a[A], c; bitset<A> f;
int main(int argc, char const *argv[]) {
while (cin >> n >> m and n and m) {
int ans = 0; f.reset(); f[0] = 1;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
cin >> c;
for (int k = 1; c; k <<= 1) {
if (k > c) k = c;
c -= k;
f |= (f << (k * a[i]));
}
}
for (int i = 1; i <= m; i++) if (f[i]) ans++;
cout << ans << endl;
}
}