zoukankan      html  css  js  c++  java
  • HDU6344 调查问卷

    状态压缩 + 模拟

    把AB串压缩成二进制,A用1表示,B用0表示。

    枚举所有问题的子集,选中的问题用1表示,其余的用0表示。对于每个子集,我们去和所有问题按位与,这样对于选中的问题,答案是A的都是1,答案是B的都是0,不同的回答得到的状态也不同。

    最后统计每个子集是否有超过k组问题不一样就行了。

    #include <bits/stdc++.h>
    #define INF 0x3f3f3f3f
    #define full(a, b) memset(a, b, sizeof a)
    #define FAST_IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
    using namespace std;
    typedef long long ll;
    inline int lowbit(int x){ return x & (-x); }
    inline int read(){
        int ret = 0, w = 0; char ch = 0;
        while(!isdigit(ch)) { w |= ch == '-'; ch = getchar(); }
        while(isdigit(ch)) ret = (ret << 3) + (ret << 1) + (ch ^ 48), ch = getchar();
        return w ? -ret : ret;
    }
    inline int gcd(int a, int b){ return b ? gcd(b, a % b) : a; }
    inline int lcm(int a, int b){ return a / gcd(a, b) * b; }
    template <typename T>
    inline T max(T x, T y, T z){ return max(max(x, y), z); }
    template <typename T>
    inline T min(T x, T y, T z){ return min(min(x, y), z); }
    template <typename A, typename B, typename C>
    inline A fpow(A x, B p, C lyd){
        A ans = 1;
        for(; p; p >>= 1, x = 1LL * x * x % lyd)if(p & 1)ans = 1LL * x * ans % lyd;
        return ans;
    }
    const int N = 5005;
    int _, a[N], n, m, k, h[N];
    
    int main(){
        int cs = 0;
        for(_ = read(); _; _ --){
            full(a, 0), full(h, 0);
            n = read(), m = read(), k = read();
            for(int i = 1; i <= n; i ++){
                string s;
                cin >> s;
                for(int j = 0; j <= m - 1; j ++){
                    if(s[j] == 'A') a[i] += (1 << (m - 1 - j));
                }
            }
            int ans = 0;
            for(int i = 0; i < (1 << m); i ++){
                int cnt = 0;
                full(h, 0);
                for(int j = 1; j <= n; j ++){
                    h[i & a[j]] ++;
                    cnt += j - h[i & a[j]];
                }
                if(cnt >= k) ans ++;
            }
            printf("Case #%d: %d
    ", ++cs, ans);
        }
        return 0;
    }
    
  • 相关阅读:
    node.js的request模块
    PHP实现一个简单url路由功能
    关于seajs
    CodeIgniter集成Smarty
    node.js批量修改图片名
    Node.js创建目录实例
    Bootstrap的表单设计器
    onbeforeunload事件被a链接触发的问题
    Socket.IO + Express实现的跨浏览器、子域的聊天室
    NodeJS获取命令行后面的参数
  • 原文地址:https://www.cnblogs.com/onionQAQ/p/11191519.html
Copyright © 2011-2022 走看看