UVA 11825 Hackers' Crackdown 状态压缩dp

参考: 刘汝佳大白书p69-p70

#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <string>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <bitset>
using namespace std;

//LOOP
#define FE(i, a, b) for(int i = (a); i <= (b); ++i)
#define FED(i, b, a) for(int i = (b); i>= (a); --i)
#define REP(i, N) for(int i = 0; i < (N); ++i)
#define CLR(A,value) memset(A,value,sizeof(A))
//INPUT
#define RI(n) scanf("%d", &n)
#define RII(n, m) scanf("%d%d", &n, &m)
#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define RS(s) scanf("%s", s)
typedef long long LL;
const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-10;
const int MAXN = 31000;

int ALL;
int dp[1 << 17];
int s[1 << 17];
int si[20];

int main()
{
    int n;
    int xn, x;
    int nc = 1;
    while (~RI(n) && n)
    {
        ALL = (1 << n) - 1;
        REP(i, n)
        {
            si[i] = (1 << i);
            RI(xn);
            while (xn--)
            {
                RI(x);
                si[i] |= (1 << x);
            }
        }
        CLR(s, 0);
        REP(ss, ALL + 1)
        {
            REP(i, n)
            {
                if (ss & (1 << i))
                  s[ss] |= si[i];
            }
        }
        CLR(dp, 0);
        REP(ss, ALL + 1)
        {
            for (int rr = ss; rr ; rr = (rr - 1) & ss)
                if (s[rr] == ALL)
                {
                    dp[ss] = max(dp[ss], dp[ss ^ rr] + 1);
                }
        }
        printf("Case %d: %d\n", nc++, dp[ALL]);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值