Network saboteur
Time Limit: 2000MS |
|
Memory Limit: 65536K |
Total Submissions: 10391 |
|
Accepted: 4990 |
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
Test instructions: Divides the number of n into two sets, which is the largest of all the numbers in one set to the other.
1#include <iostream>2#include <cstring>3#include <string.h>4#include <algorithm>5#include <cstdio>6 7 using namespacestd;8 Const intMAX = A;9 intA[max][max],v[max],b[max];Ten intn,cnt,sum; One voidDfsintXintsum) A { -V[X] =1; - for(inti =1; I <= N; i++) the { - if(V[i] = =0) -Sum + =A[x][i]; - Else +Sum-=A[x][i]; - } +CNT =Max (cnt,sum); A for(inti = x +1; I <= N; i++)//this attention, in fact, can think of, before the path is the reverse order is also a case, this is a set, so the reverse order and the original is a situation, so there is no need to start the cycle from 0, 0,1 and 1,0 is a situation at { - DFS (i,sum); -V[i] =0; - } - } - intMain () in { - while(SCANF ("%d", &n)! =EOF) to { + for(inti =1; I <= N; i++) - { the for(intj =1; J <= N; J + +) * { $scanf"%d", &a[i][j]);Panax Notoginseng } - } thememset (V,0,sizeof(v)); +CNT =0; ADfs1,0); theprintf"%d\n", CNT); + } - return 0; $}
View Code
Poj2531network saboteur (dfs+ pruning)