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解题报告(dfs+剪枝)

题目大意:给你一个n*n(1-20)的矩阵,矩阵里的每个数c[i][j]

Network Saboteur (poj 2531 dfs)

题意:给一个无向图,把它分成两部分,使得连接这两部分边的权和最大。 思路:定义一个group数组标记每个点的分组,从0号点dfs直到N,暴搜所有情况求最大值。...

poj2531 Network Saboteur

Description A university network is composed of N computers. System administrators gathered infor...

DFS Network Saboteur poj 2531

DFS Network Saboteur poj 2531

POJ 2531-Network Saboteur(N个点分成两部分)

Network Saboteur Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12566 ...
  • MIKASA3
  • MIKASA3
  • 2017年02月18日 17:13
  • 180

poj 2531 Network Saboteur

Network Saboteur Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8822 ...
  • ctxdecs
  • ctxdecs
  • 2014年04月24日 14:20
  • 656

POJ2531.Network Saboteur

试题请参见: http://poj.org/problem?id=2531题目概述A university network is composed of N computers. System ad...
  • zjhzxhz
  • zjhzxhz
  • 2015年08月06日 16:31
  • 1539

poj 2531 Network Saboteur(DFS,题意)

Description A university network is composed of N computers. System administrators gathered informat...

【Poj 2531】 Network Saboteur dfs

Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10712 Acce...
  • ALPS233
  • ALPS233
  • 2016年03月22日 21:40
  • 300

poj 2531 Network Saboteur(dfs)

题意:有n个点,把这些点分别放到两个集合里,在两个集合的每个点之间都会有权值,求可能形成的最大权值。 n 看网上还有用NP、随机化什么什么的。。。都不会 等学了再回过来看看吧 代...
  • CillyB
  • CillyB
  • 2016年11月05日 23:10
  • 142
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:POJ 2531 - Network Saboteur
举报原因:
原因补充:

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