POJ ---2531
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 8751 | Accepted: 4070 |
Description
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
Output file must contain a single integer -- the maximum traffic between the subnetworks.
Output
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的更多相关文章
- poj 2531 Network Saboteur( dfs )
题目:http://poj.org/problem?id=2531 题意:一个矩阵,分成两个集合,求最大的 阻碍量 改的 一位大神的代码,比较简洁 #include<stdio.h> #i ...
- POJ 2531 Network Saboteur
http://poj.org/problem?id=2531 题意 :有N台电脑,每两台电脑之间都有个通信量C[i][j]; 问如何将其分成两个子网,能使得子网之间的通信量最大. 也就是说将所有节点分 ...
- POJ 2531 Network Saboteur 位运算子集枚举
题目: http://poj.org/problem?id=2531 这个题虽然是个最大割问题,但是分到dfs里了,因为节点数较少.. 我试着位运算枚举了一下,开始超时了,剪了下枝,1079MS过了. ...
- poj 2531(dfs)
题目链接:http://poj.org/problem?id=2531 思路:由于N才20,可以dfs爆搞,枚举所有的情况,复杂度为2^(n). #include<iostream> #i ...
- poj 2531 Network Saboteur 解题报告
题目链接:http://poj.org/problem?id=2531 题目意思:将 n 个点分成两个部分A和B(也就是两个子集啦), 使得子集和最大(一定很难理解吧,呵呵).举个例子吧,对于样例,最 ...
- POJ 2531 Network Saboteur (枚举+剪枝)
题意:给你一个图,图中点之间会有边权,现在问题是把图分成两部分,使得两部分之间边权之和最大. 目前我所知道的有四种做法: 方法一:状态压缩 #include <iostream> #inc ...
- poj 2531 Network Saboteur(经典dfs)
题目大意:有n个点,把这些点分别放到两个集合里,在两个集合的每个点之间都会有权值,求可能形成的最大权值. 思路:1.把这两个集合标记为0和1,先默认所有点都在集合0里. 2 ...
- POJ 2531 暴力深搜
Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13494 Accepted: 6543 ...
- poj 2531 搜索剪枝
Network Saboteur Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u ...
随机推荐
- facebook登录(集成FBSDKLoginKit) result的isCancelled总是YES token为nil
只需要在AppDelegate如下函数添加: - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDict ...
- C/C++随机数rand()和种子函数srand()
在计算机编程中,常常要产生一个随机数.但是要让计算机产生一个随机数并不那么容易.计算机的执行,是以代码来进行的,所以并不可能像抽牌,扔骰子那样产生一个真正具有随机意义的数.只可能以一定的算法产生一个伪 ...
- requirejs实践二 加载其它JavaScript与运行
上一篇中介绍了requirejs加载JavaScript文件,在这一篇中介绍加载JavaScript后执行代码 这次是test2.html文件, <!DOCTYPE html> <h ...
- ZOJ 1025 Wooden Sticks(快排+贪心)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=25 题目大意:机器运送n个木条,每个木条有一个长度和重量.运送第一根木 ...
- OpenCV(5)-图像掩码操作(卷积)-锐化
锐化概念 图像平滑过程是去除噪声的过程.图像的主要能量在低频部分,而噪声主要集中在高频部分.图像的边缘信息主要也在高频部分,在平滑处理后,将会丢不部分边缘信息.因此需要使用锐化技术来增强边缘. 平滑处 ...
- _itoa_s, _i64toa_s, _ui64toa_s, _itow_s, _i64tow_s, _ui64tow_s
Converts an integer to a string. These are versions of _itoa, _i64toa, _ui64toa, _itow, _i64tow, _ui ...
- 九度0J 1374 所有员工年龄排序
题目地址:http://ac.jobdu.com/problem.php?pid=1374 题目描述: 公司现在要对所有员工的年龄进行排序,因为公司员工的人数非常多,所以要求排序算法的效率要非常高,你 ...
- open()函数
STDOUT_FILENO 1 标准输入 STDIN_FILENO 0 标准输出 STDERR_FILENO 2 标准错误 在/proc目 ...
- easy ui tabs 顶部绑定事件
$(function(){ $('#tb').tabs('bindclick', function(index, title){ }); }); $.extend($.fn.tabs. ...
- Flume用来收集日志,zeppelin用来展示
Flume:Flume是一个分布式,可依赖的,用于高效率的收集.聚类.移动大量数据的服务.Flume使用基于流数据的简单而且可扩展的架构.由于拥有可调的依赖机制和许多故障恢复机制,Flume是健壮而且 ...