# POJ 2531 - Network Saboteur

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

#include <cstdio>
#include <cstring>

int maps[25][25];
bool vis[25];
int maxn;
int n;

void solve(int step)
{
int sum = 0;
if (step == n)
{
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
if (vis[i] == true && vis[j] == false)
sum += maps[i][j];
}
}
if (sum > maxn)
maxn = sum;
return;
}
vis[step] = false;
solve(step + 1);
vis[step] = true;
solve(step + 1);
}

int main()
{
scanf("%d", &n);
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
scanf("%d", &maps[i][j]);

memset(vis, false, sizeof(vis));
maxn = 0;
solve(1);
printf("%d\n", maxn);
return 0;
}


• 本文已收录于以下专栏：

## 【POJ 2531】Network Saboteur

【POJ 2531】Network Saboteur图的搜索 剪枝真是门学问。。剪好了快的可真不是一倍两倍刚开始搜的思路有问题 TLE了 后来枚举点暴力搜了一发 两百多ms由于查找时权值是不断增加的 ...
• ChallengerRumble
• 2015年08月10日 11:15
• 635

## POJ 2531 Network Saboteur

Network Saboteur Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7751 ...
• ACM2272902662
• 2013年01月23日 20:42
• 466

## POJ 2531 Network Saboteur

• lin375691011
• 2013年08月21日 16:44
• 3952

## Network Saboteur(POJ 2531)

Description A university network is composed of N computers. System administrators gathered inf...
• luckyrass
• 2015年01月29日 16:14
• 288

## poj 2531 Network Saboteur

• acm_code
• 2014年11月07日 09:53
• 603

## poj 2531 Network Saboteur

• purevegetable
• 2013年09月02日 13:56
• 494

## poj 2531 Network Saboteur

• txgANG
• 2016年08月16日 21:27
• 121

## POJ 2531 Network Saboteur（搜索）

Network Saboteur Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10084 ...
• yeguxin
• 2015年08月03日 10:45
• 422

## poj 2531: Network Saboteur

• u010663294
• 2014年07月03日 12:52
• 274

## Poj 2531 Network Saboteur

Network Saboteur Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9533 ...
• u013082590
• 2015年02月13日 13:45
• 248

举报原因： 您举报文章：POJ 2531 - Network Saboteur 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)