Network saboteur
Time Limit: 2000MS |
|
Memory Limit: 65536K |
Total Submissions: 10216 |
|
Accepted: 4885 |
Description
A University Network is composed of N computers. System administrators gathered information on the traffic between nodes, and carefully divided the network into and the subnet Works in order to minimize traffic between parts.
A disgruntled computer science student Vasya, after being expelled from the university, decided to has his revenge. He hacked into the university network and decided to reassign computers to maximize the traffic between.
Unfortunately, he found, calculating such worst subdivision is one of the those problems he, being a student, failed to so Lve. So he asks-a more successful CS student, to-help him.
The traffic data is given in the form of Matrix C, where Cij is the amount of data sent between and ith jth (nodes = Cji, Cii = 0). The goal is to divide the network nodes into the and the disjointed subsets A and B so as to maximize the SUM∑CIJ (I∈A,J∈B).
Input
The first line of input contains a number of nodes N (2 <= n <= 20). The following n lines, containing n space-separated integers each, represent the traffic matrix C (0 <= Cij <= 10000 ).
Output file must contain a single integer-the maximum traffic between the subnetworks.
Output
Output must contain a single integer-the maximum traffic between the subnetworks.
Sample Input
30 50 3050 0 4030 40 0
Sample Output
90
The main topic: There are two sets, not the maximum path between the collection and.
#include <iostream> #include <cstdio> #include <string.h> #include <string> #include <cmath > #include <queue> #define MOD 9901#define LL long longusing namespace Std;int n;int a[32][32];bool vis[32];int ans void dfs (int s,int sum) { vis[s]=true;//uses a tag array to divide two sets for (int i=1;i<=n;i++) { if (vis[i])// If the current number in the collection is subtracted from the current number to the distance of the collection sum-=a[s][i]; else sum+=a[s][i];//otherwise add } Ans=max (Sum,ans); for (int i=s+1;i<=n;i++)//Enumerates the next point and joins the set { vis[i]=true; DFS (i,sum); Vis[i]=false;} } int main () { while (scanf ("%d", &n)!=eof) { ans=0; for (int i=1;i<=n;i++) { for (int j=1;j<=n;j++) { scanf ("%d", &a[i][j]); } } memset (vis,false,sizeof (Vis)); DFS (1,0); printf ("%d\n", ans); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
POJ 2531 Network saboteur (DFS)