Network Saboteur
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 8751   Accepted: 4070

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

思路:通过位运算来枚举集合,由于集合的互补性只需要枚举2^(n-1)个集合。

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int map[][];
int main(){
int N, temp, flow, ans;
//freopen("in.c", "r", stdin);
while(~scanf("%d", &N)){
for(int i = ;i <= N;i ++){
for(int j = ;j <= N;j ++)
scanf("%d", &map[i][j]);
}
ans = -;
for(int i = ;i <= ( << N-);i ++){
flow = ;
for(int j = ;j <= ;j ++){
if(i & ( << j)){
for(int k = ;k <= ;k ++){
if(!(i & ( << k))) flow += map[j+][k+];
}
}
}
ans = max(ans, flow);
}
printf("%d\n", ans);
}
}
												

POJ ---2531的更多相关文章

  1. poj 2531 Network Saboteur( dfs )

    题目:http://poj.org/problem?id=2531 题意:一个矩阵,分成两个集合,求最大的 阻碍量 改的 一位大神的代码,比较简洁 #include<stdio.h> #i ...

  2. POJ 2531 Network Saboteur

    http://poj.org/problem?id=2531 题意 :有N台电脑,每两台电脑之间都有个通信量C[i][j]; 问如何将其分成两个子网,能使得子网之间的通信量最大. 也就是说将所有节点分 ...

  3. POJ 2531 Network Saboteur 位运算子集枚举

    题目: http://poj.org/problem?id=2531 这个题虽然是个最大割问题,但是分到dfs里了,因为节点数较少.. 我试着位运算枚举了一下,开始超时了,剪了下枝,1079MS过了. ...

  4. poj 2531(dfs)

    题目链接:http://poj.org/problem?id=2531 思路:由于N才20,可以dfs爆搞,枚举所有的情况,复杂度为2^(n). #include<iostream> #i ...

  5. poj 2531 Network Saboteur 解题报告

    题目链接:http://poj.org/problem?id=2531 题目意思:将 n 个点分成两个部分A和B(也就是两个子集啦), 使得子集和最大(一定很难理解吧,呵呵).举个例子吧,对于样例,最 ...

  6. POJ 2531 Network Saboteur (枚举+剪枝)

    题意:给你一个图,图中点之间会有边权,现在问题是把图分成两部分,使得两部分之间边权之和最大. 目前我所知道的有四种做法: 方法一:状态压缩 #include <iostream> #inc ...

  7. poj 2531 Network Saboteur(经典dfs)

    题目大意:有n个点,把这些点分别放到两个集合里,在两个集合的每个点之间都会有权值,求可能形成的最大权值.   思路:1.把这两个集合标记为0和1,先默认所有点都在集合0里.             2 ...

  8. POJ 2531 暴力深搜

    Network Saboteur Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13494   Accepted: 6543 ...

  9. poj 2531 搜索剪枝

    Network Saboteur Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u ...

随机推荐

  1. AudioStreamer使用之快速点击下/上一首按钮,音频会重复的问题解决。

    针对此问题,我的做法是在AudioStreamer.h文件新加入一个属性 @property (nonatomic,strong) NSURL *musicUrl; 和一个单例方法: +(id)sha ...

  2. IOS开发之KVC与KVO简述

    KVC:Key-Value Coding KVO:Key-Value Observing Person.m #import <Foundation/Foundation.h> @inter ...

  3. 2014年12月20日00:33:14-遮罩+进度条-extjs form.isvalid

    1.Extjs : 遮罩+进度条 2.Extjs: extjs form.isvalid http://stackoverflow.com/questions/19354433/extjs-form- ...

  4. bzoj2679:[Usaco2012 Open]Balanced Cow Subsets

    思路:折半搜索,每个数的状态只有三种:不选.选入集合A.选入集合B,然后就暴搜出其中一半,插入hash表,然后再暴搜另一半,在hash表里查找就好了. #include<iostream> ...

  5. 访问Access数据库(有多个数据库时 体现多态)

    如果想编写单机版MIS.小型网站等对数据库性能要求不高的系统,又不想安装SQLServer,可以使用Access(MDAC),只要一个mdb文件就可以了.使用Access创建mdb文件,建表.OleD ...

  6. ubuntu desktop 开机 连接网络

    参考   http://linux.net527.cn/Ubuntu/Ubuntuanzhuangyuyingyong/2490.html

  7. problem 1 -- Two sum

    很简单.没什么好说的.但是在阿里实习的第四面的时候居然问到了. 大意是给出一组无序数列和目标数Z,在无序数列中找到X和Y,使得X+Y=Z. 有两种方法: 一种是排序后,同时首尾搜索.时间复杂度为O(n ...

  8. Ubuntu下Java环境配置

    Oracle Java安装: 通过以下命令进行安装: sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt ...

  9. 根据日期自增的sql语句

    Insert into wd_orderitem (count , id_dish , state , info , sn , id_order)values(1 , 1000000001 , 3 , ...

  10. xml转array

    1.字串 $xml = simplexml_load_string($data);$array = json_decode(json_encode($xml),TRUE); 2.文件$xml = si ...