POJ 2531 - Network Saboteur

原创 2016年08月29日 20:36:46

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


题意:有这样一个集合,集合中不同元素之间有相应的值,让你将这个集合分成两个集合,使这个集合中每个元素到另一集合中所有元素的值的和最大。

直接DFS搜索即可,用 true 和 false 来标记两个集合,每次搜索看这个元素是否属于这个集合。

#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;
}


版权声明:Designed by Sureina 2016©Copyright.All Right Reserved

【POJ 2531】Network Saboteur

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

POJ 2531 Network Saboteur

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

POJ 2531 Network Saboteur

这题一开始怎么想也想不出搜索来, 后来才明白原来是这样。 这是一个DFS暴搜,呵呵…… 下面是代码: #include #include const int M=25; int n,map1[M]...
  • lin375691011
  • 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
  • luckyrass
  • 2015年01月29日 16:14
  • 288

poj 2531 Network Saboteur

题意:给定一个完全图,求将其分为两部分的边权值和最大 如:题中第一组样例: 3 0 50 30 50 0 40 30 40 0 将顶点分为两个集合A={2},B={1,3},sum=C21+C23=9...
  • acm_code
  • acm_code
  • 2014年11月07日 09:53
  • 603

poj 2531 Network Saboteur

简单的dfs,题意为:将整个分为2部分,相同部分的通信无话费,求最大的话费。 #include #include #include #define MAX(a1,b1) (a1)>(b1)?(a1)...
  • purevegetable
  • purevegetable
  • 2013年09月02日 13:56
  • 494

poj 2531 Network Saboteur

题目链接:点击打开链接 Description A university network is composed of N computers. System administrators g...
  • txgANG
  • txgANG
  • 2016年08月16日 21:27
  • 121

POJ 2531 Network Saboteur(搜索)

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

poj 2531: Network Saboteur

解题思路: DFS
  • u010663294
  • u010663294
  • 2014年07月03日 12:52
  • 274

Poj 2531 Network Saboteur

Network Saboteur Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9533 ...
  • u013082590
  • u013082590
  • 2015年02月13日 13:45
  • 248
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:POJ 2531 - Network Saboteur
举报原因:
原因补充:

(最多只允许输入30个字)