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 ...
随机推荐
- MyEclipse 多项目对应配置多个Tomcat
在MyEclipse的安装目录下,有D:\Program Files\MyEclipse 6.5\myeclipse\eclipse\plugins 的插件路径. 里边很多插件的配置文件包. 找到 ...
- hibernate_validator_01
1.环境准备(Maven工程) <?xml version="1.0" encoding="UTF-8"?> <project xmlns=& ...
- 15_动态SQL
[UserMapper.xml]和之前的作对比 <mapper namespace="com.Higgin.Mybatis.mapper.UserMapper"> &l ...
- 解决Mysql的主从数据库没有同步的两种方法
今天发现Mysql的主从数据库没有同步 先上Master库: mysql>show processlist; 查看下进程是否Sleep太多.发现很正常.show master status; ...
- scp 命令使用
scp 是secure copy的简写,用于在Linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝不能跨服务器,而且 scp传输是加密的.可能会稍微影响一下速度.当你服 ...
- js异步脚本
1.延迟脚本 HTML4.01为<script>标签定义了defer属性,为了表明脚本在执行时不会影响页面的构造.也就是说,脚本会在整个页面都解析完毕后再运行.因此在<script& ...
- J2EE中的HttpSession
J2EE中的HttpSession总结: ①什么是session? session是服务器端技术,利用这个技术,服务器在运行时可以为每一个浏览器创建一个共享的session对象,由于 session为 ...
- 转载“用USBOOT制作DOS启动盘”
使用软件: Usboot和MaxDOS_5.6s_U盘版. 由于我的U盘容量比较小,暂时只能做DOS启动功能,其它功能如Windows PE,等我以后测试成功后再补充说明. U盘是啥? 读音优盘,可以 ...
- nexus3添加第三方jar
最近在看maven的打包及管理,然後就看到nexus,自己在安裝的時候就下載了最新版的nexus-3.2.0-01-win64,按照文档部署后启动,浏览.之前一致使用的是2.0的,所以还是需要导出点点 ...
- java项目打成jar包时引用了第三方jar,此时我们该如何解决呢
Web项目做多了,反而对单纯的java项目陌生了,今天我们在开发项目的过程中,碰到一个这样的需求:需要将java项目放到linux系统上跑起来,当然这个javaSE项目是带main方法的.我们知道在I ...