使用 bitset 优化背包判断,时间复杂度\Theta\!\left(\frac{nk}w\right)

#include <bitset>
#include <iostream>
using namespace std;

int n;
int k;
bitset<1001> have = 1;

void Solve() {
    cin >> n >> k;
    int v;
    while (cin >> v) {
        have |= have << v;
    }
    cout << (have[k] ? "Yes" : "No");
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Solve();
    return 0;
}
// 64 位输出请用 printf("%lld")