UVA11825 Hacker's Crackdown

Hackers' Crackdown

 

https://vjudge.net/problem/UVA-11825

 

题目大意:n台电脑,n中服务,每台电脑有全部的服务,每台电脑可以选择一种服务,使得这台电脑和它连接的电脑服务终止。问最多能让多少种服务完全瘫痪,一种服务完全瘫痪是指没有任何一台电脑运行这种服务

 

每台电脑和它所连的电脑构成一个集合,问题变为有若干集合,将他们进行合并,最多能合并成多少全集。

 

state[i]表示电脑i构成的集合

uni[S]表示S中电脑的集合的并

dp[S]表示S中电脑的集合最多合并成多少全集

dp[S] = max(dp[S], dp[S - SS]),SS为S子集且uni[SS]为全集

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cstdlib>
 5 #include <algorithm>
 6 #include <queue>
 7 #include <vector>
 8 #define min(a, b) ((a) < (b) ? (a) : (b))
 9 #define max(a, b) ((a) > (b) ? (a) : (b))
10 #define abs(a) ((a) < 0 ? (-1 * (a)) : (a))
11 inline void swap(int &a, int &b)
12 {
13     int tmp = a;a = b;b = tmp;
14 }
15 inline void read(int &x)
16 {
17     x = 0;char ch = getchar(), c = ch;
18     while(ch < '0' || ch > '9') c = ch, ch = getchar();
19     while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
20     if(c == '-') x = -x;
21 }
22 
23 const int INF = 0x3f3f3f3f;
24 
25 int n, uni[1 << 16], state[17], dp[1 << 16], ma, ans, t;
26 
27 int main()
28 {
29     while(scanf("%d", &n) != EOF && n)
30     {
31         ++ t;
32         memset(state, 0, sizeof(state));
33         memset(uni, 0, sizeof(uni));
34         memset(dp, 0, sizeof(dp));
35         for(register int i = 0;i < n;++ i)
36         {
37             int tmp1, tmp2;read(tmp1);
38             state[i] |= (1 << i); 
39             for(register int j = 1;j <= tmp1;++ j)
40                 read(tmp2), state[i] |= (1 << tmp2);
41         }
42         ma = 1 << n;ans = 0;
43         for(register int S = 0;S < ma;++ S)
44             for(register int i = 0;i < n;++ i)
45                 if(S & (1 << i)) uni[S] |= state[i];
46         for(register int S = 0;S < ma;++ S)
47             for(register int SS = S;SS;SS = (SS - 1) & S)
48                 if(uni[SS] == ma - 1) dp[S] = max(dp[S], dp[S ^ SS] + 1);
49         printf("Case %d: %d\n", t, dp[ma - 1]);
50     }
51     return 0;
52 }
UVA11825

 

posted @ 2018-01-17 08:21  嘒彼小星  阅读(214)  评论(0编辑  收藏  举报