bitset 优化背包判断

01背包前置题

https://www.nowcoder.com/practice/c227e9845d714ca6a27c86f1f9db0ee4

使用 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")

全部评论
厉害啊大佬5555555
点赞 回复 分享
发布于 今天 11:03 湖北

相关推荐

03-08 18:11
门头沟学院 Java
Java抽象小篮子:海投就完事了,简历没什么问题,最大问题是学历
点赞 评论 收藏
分享
04-03 15:12
已编辑
门头沟学院 Java
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务