题解 | 小心火烛的歪

小心火烛的歪

https://www.nowcoder.com/practice/6cdb80dbb66c42eea179068a4afb25db

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

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    bitset<49> a, b[7];
    string s, t;
    for (int i = 1; i <= n; i++)
        cin >> t, s += t;
    a = bitset<49>(s);
    for (int k = 0; k < q; k++) {
        s = "";
        for (int i = 1; i <= n; i++)
            cin >> t, s += t;
        b[k] = bitset<49>(s);
    }
    int mn = q + 1, res;
    for (int i = 0; i < 1 << q; i++) {
        if (__builtin_popcount(i) >= mn)
            continue;
        bitset<49> ans;
        for (int j = 0; j < q; j++)
            if (i >> j & 1)
                ans |= b[j];
        if ((ans | a) == (1ll << m * n) - 1 && (ans & a) == 0)
            mn = __builtin_popcount(i), res = i;
    }
    if (mn == q + 1)
        mn = -1;
    cout << mn << '\n';
    if (mn != -1) {
        for (int j = 0; j < q; j++)
            if (res >> j & 1)
                cout << j + 1 << ' ';
        cout << '\n';
    }

    return 0;
}

全部评论

相关推荐

用微笑面对困难:不是你千万别小看这家公司,他们的预估市值成倍上涨,三次在报告看见这个公司了,总之如果是给股权的话可以试试,未来没准真能发家致富哈哈哈哈
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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