Uva 11825 - Hackers'Crackdown 상태 압축
Problem H
Hackers’ Crackdown Input: Standard Input
Output: Standard Output
Miracle Corporations has a number of system services running in a distributed computer system which is a prime target for hackers. The system is basically a set of N computer nodes with each of them running a set of N services. Note that, the set of services running on every node is same everywhere in the network. A hacker can destroy a service by running a specialized exploit for that service in all the nodes.
One day, a smart hacker collects necessary exploits for all these N services and launches an attack on the system. He finds a security hole that gives him just enough time to run a single exploit in each computer. These exploits have the characteristic that, its successfully infects the computer where it was originally run and all the neighbor computers of that node.
Given a network description, find the maximum number of services that the hacker can damage.
Input
There will be multiple test cases in the input file. A test case begins with an integer N (1<=N<=16), the number of nodes in the network. The nodes are denoted by 0 to N - 1. Each of the following N lines describes the neighbors of a node. Line i (0<=i
The end of input will be denoted by a case with N = 0. This case should not be processed.
Output
For each test case, print a line in the format, “Case X: Y”, where X is the case number & Y is the maximum possible number of services that can be damaged.
Sample Input
Output for Sample Input
3 2 1 2 2 0 2 2 0 1 4 1 1 1 0 1 3 1 2 0
Case 1: 3 Case 2: 2
Problemsetter: Mohammad Mahmudur Rahman
Special Thanks Manzurur Rahman Khan ----------
n개 집합 p1, p2...pn은 가능한 한 여러 조로 나뉘어 각 조의 모든 집합의 합집합이 전체 집합과 같다.
p[i]는 i와 인접한 컴퓨터의 집합을 나타낸다
cover[s]는 약간의 p[i]가 집합된 것을 나타낸다
f[s]는 서브집합s가 최대 몇 조로 나눌 수 있는지 나타낸다
f[s]=max{f[s0]|s0은 s의 서브집합이고cover[s0]는 전집합}+1이다.
----------
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=18;
const int maxs=1<<18;
int f[maxs];
int p[maxn];
int cover[maxs];
int n;
int main()
{
int cas=0;
while (~scanf("%d",&n))
{
if (n==0) break;
for (int i=0;i<n;i++)
{
int m,x;
scanf("%d",&m);
p[i]=1<<i;
while (m--)
{
scanf("%d",&x);
p[i]|=(1<<x);
}
}
for (int s=0;s<(1<<n);s++)
{
cover[s]=0;
for (int i=0;i<n;i++)
{
if (s&(1<<i))
{
cover[s]|=p[i];
}
}
}
f[0]=0;
int ALL=(1<<n)-1;
for (int s=1;s<(1<<n);s++)
{
f[s]=0;
for (int s0=s;s0;s0=(s0-1)&s)
{
if (cover[s0]==ALL)
{
f[s]=max(f[s],f[s^s0]+1);
}
}
}
printf("Case %d: %d
",++cas,f[ALL]);
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
49일차 - 2022.04.20Baekjoon에서 문제풀이 1) 문제 : 첫째 줄에는 별 1개, 둘째 줄에는 별 2개, N번째 줄에는 별 N개를 찍는 문제/ 첫째 줄에 N(1 ≤ N ≤ 100)이 주어진다. 첫째 줄부터 N번째 줄까지 차례대로 별...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.