• BZOJ 1688: [Usaco2005 Open]Disease Manangement 疾病管理 状压DP + 二进制 + 骚操作


    Description

    Alas! A set of D (1 <= D <= 15) diseases (numbered 1..D) is running through the farm. Farmer John would like to milk as many of his N (1 <= N <= 1,000) cows as possible. If the milked cows carry more than K (1 <= K <= D) different diseases among them, then the milk will be too contaminated and will have to be discarded in its entirety. Please help determine the largest number of cows FJ can milk without having to discard the milk.

    Input

    * Line 1: Three space-separated integers: N, D, and K * Lines 2..N+1: Line i+1 describes the diseases of cow i with a list of 1 or more space-separated integers. The first integer, d_i, is the count of cow i's diseases; the next d_i integers enumerate the actual diseases. Of course, the list is empty if d_i is 0. 有N头牛,它们可能患有D种病,现在从这些牛中选出若干头来,但选出来的牛患病的集合中不过超过K种病.

    Output

    * Line 1: M, the maximum number of cows which can be milked.

    题解: 

    $lowbit(i)$ 的定义为 $i$ 的最后一个 $1$ 所对应的那个二进制串(我好像也不太能用一句话解释得清).
    树状数组中这是一个必备的工具,在状压 DP 中用这个也是十分方便的. 
    例如,要更新 $i$ 的二进制形式中 $1$ 的数量就可以用 $Num(i-lowbit(i))+1$ 来更新.
    在本题中,我们先预处理出每一个患病数小于等于 $k$ 的所有子集.
    每次读入的时候枚举一下,并更新到答案即可. 
    #include <bits/stdc++.h>
    #define setIO(s) freopen(s".in","r",stdin) 
    #define maxn 100000 
    using namespace std;
    int F[1 << 16], s[1 << 16], v[1 << 16], f[1 << 16];  
    int n, D, k, tot = 0, ans = 0; 
    int main()
    {
        // setIO("input"); 
        scanf("%d%d%d",&n,&D,&k);
        for(int i = 1; i < (1 << D); ++i)
        {
            s[i] = s[i - (i & -i)] + 1; 
            if(s[i] <= k) v[++tot] = i; 
        }
        for(int i = 1; i <= n; ++i)
        {
            int a, b; 
            scanf("%d",&a); 
            int t = 0;
            for(int j = 1; j <= a; ++j)
            {
                scanf("%d",&b); 
                t += (1 << (b - 1));  
            }
            for(int j = 1; j <= tot; ++j)
            {
                if((v[j] & t) == t) 
                    ++f[j], ans = max(ans, f[j]); 
            }
        }
        printf("%d
    ",ans); 
        return 0; 
    }
    

      

  • 相关阅读:
    常用操作
    vue cropper
    Tensorflow学习笔记5: Object_detection之训练PASCAL VOC数据集
    Tensorflow学习笔记4: Object_detection之准备数据生成TFRecord
    Tensorflow学习笔记3: Object_detection之配置Training Pipeline
    Tensorflow学习笔记2: Object_detection之liunx服务器安装部署步骤记录
    OpenCV-python学习笔记1:CV2和PIL按box信息实现图像裁剪
    Tensorflow学习笔记1:Object_detection之模型训练日志结果解析
    python-OS.path.join()路径拼接
    python-几种快速了解函数及模块功能的方式
  • 原文地址:https://www.cnblogs.com/guangheli/p/10986744.html
Copyright © 2020-2023  润新知