Uva 11825 Hackers ' crackdown ACM Problem solving report (pressure DP)

Source: Internet
Author: User

The problem of test instructions is that there are n computers, each computer has n services, and then each computer and a few computers next to each other, there is a hacker can stop a service on each computer, and then this computer and the computer adjacent to it will stop, ask the maximum number of services can be stopped.

The problem is to put the relationship between computers into a set, because the range of n is smaller, so can state compression, with (1<<n)-1 represents the complete computer, and then each computer and its adjacent computer can be used p[i] binary record, and then open a cover array, subscript to take a subset of the complete set , look at the subsets of these computers plus their neighboring computers, meaning to stop a service on the selected computers, plus the computers they affect, can cover the entire collection (n computers).

State transfer F[s]=max (F[S-S0]) +1,S0 is a subset of S, cover[s0]= complete.

#include <iostream> #include <cstdio> #include <cctype> #include <cstdlib> #include <cmath > #include <algorithm> #include <cstring> #include <string> #include <vector> #include <
queue> #include <map> #include <set> #include <sstream> #include <stack> using namespace std;
#define MAX, a typedef long long LL;
const double pi=3.141592653589793;
const int INF=1E9;
const double INF=1E20;
const double eps=1e-6;
int cover[70000],f[70000];
	int main () {int n,m,x,kase=0;
	int p[20];
		while (cin>>n&&n) {kase++;
			for (int i=0;i<n;i++) {cin>>m;
			P[i]= (1<<i);
				while (m--) {cin>>x;
			P[i]|= (1&LT;&LT;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=0;s<=all;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\n", Kase,f[all]);
} return 0;
 }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.