POJ2531 Network Saboteur

                                                                                Network Saboteur

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 4515   Accepted: 1889

Description

A university network is composed of N computers. System administrators gathered information on the traffic between nodes, and carefully divided the network into two subnetworks in order to minimize traffic between parts.
A disgruntled computer science student Vasya, after being expelled from the university, decided to have his revenge. He hacked into the university network and decided to reassign computers to maximize the traffic between two subnetworks.
Unfortunately, he found that calculating such worst subdivision is one of those problems he, being a student, failed to solve. So he asks you, a more successful CS student, to help him.
The traffic data are given in the form of matrix C, where Cij is the amount of data sent between ith and jth nodes (Cij = Cji, Cii = 0). The goal is to divide the network nodes into the two 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

3
0 50 30
50 0 40
30 40 0

Sample Output

90

Source

Northeastern Europe 2002, Far-Eastern Subregion

 

 1 #include <cstdlib>
 2 #include <iostream>
 3 #include <string.h>
 4 #include <cstdio>
 5 using namespace std;
 6 int data[21][21];
 7 int a[21];
 8 int mount=0;
 9 
10 int n;
11 int dfs(int s,int num)
12 {int i,j;
13 
14 if(num==0)
15 {         int sum=0;
16           for(i=1;i<=n;i++)
17           {if(a[i]==0)
18            continue;
19            
20            for(j=1;j<=n;j++)
21            {if(a[j])
22             continue;
23             sum+=data[i][j];
24             
25            }
26           }
27           
28           if(sum>mount)
29           mount=sum;
30           return 1;
31 }
32 
33 for(i=s;i<=n;i++)
34 {
35                  if(a[i])
36                  continue;
37                  a[i]=1;
38                  dfs(i+1,num-1);
39                  a[i]=0;
40     
41 }
42 
43 return 0;
44 }
45 
46 
47 
48 int main(int argc, char *argv[])
49 {
50 cin>>n;
51 int i,j;
52 for(i=1;i<=n;i++)
53 for(j=1;j<=n;j++)
54 cin>>data[i][j];
55 mount=0;
56 
57 memset(a,0,sizeof(a));
58 for(i=1;i<=n/2;i++)
59 dfs(1,i);
60 
61 cout<<mount<<endl;
62                    
63 
64 
65     system("PAUSE");
66     return EXIT_SUCCESS;
67 }
posted @ 2012-05-31 09:58  cseriscser  阅读(256)  评论(0编辑  收藏  举报