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

看完 CQzhangyu 的代码后才知道原来代码应该是这么写的,真的好优美. 

Code:

#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\n",ans); 
    return 0; 
}

  

猜你喜欢

转载自www.cnblogs.com/guangheli/p/10986744.html