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. 04_过滤器Filter_02_Filter解决中文乱码问题

    [过滤器解决中文乱码问题实例] [工程截图] [web.xml] <?xml version="1.0" encoding="UTF-8"?> &l ...

  2. MinGW 仿 linux 开发环境

    MinGW 默认安装 MSYS.通常打开的 MinGW Shell 其实 MSYS,MinGW 作为一个组件存在. MSYS -- Minimal SYStem,是一个 Bourne Shell 解释 ...

  3. HttpHandler与HttpModule及实现文件下载

    HttpHandler:处理请求(Request)的信息和发送响应(Response).HttpModule:通过Http Module向Http请求输出流中写入文字,httpmodule先执行 它们 ...

  4. SVG

    目前SVG在国内的使用并不常见,并且关于svg的相关js库也不多,这里指出两款svg的库Snap.svg和svg.js,Snap.svg张鑫旭的博客上有关于他的使用APi http://www.zha ...

  5. 2016030208 - sql50题练习题

    数据库建表脚本和使用的数据请参考:http://www.cnblogs.com/zhtzyh2012/p/5235826.html sql50题练习参看:http://blog.sina.com.cn ...

  6. STM32之外部中断控制

    一.STM32外部中断 1.STM32外部中断结构图 如上图所示:主要包括四个环节,GPIO.AFIO.EXTI.NVIC.以STM32F103VE(100脚)为例说明硬件模块的数量: GPIO:   ...

  7. ARM GCC 内嵌汇编手册

    转自:http://blogold.chinaunix.net/u2/69404/showart_1922655.html ARM GCC 内嵌(inline)汇编手册 关于这篇文档这篇文章是本人为方 ...

  8. qt 5 基础知识 2(控件篇)

    QVBoxLayout *lay = new QVBoxLayout(this); // 创建一个竖直的盒子 lebel 篇 lay->addWidget(label = new QLabel( ...

  9. Computer Vision Applied to Super Resolution

    Capel, David, and Andrew Zisserman. "Computer vision applied to super resolution." Signal ...

  10. C++引用作为函数的参数

    引用也可以作为一个函数的参数,如:我们定义交换两个数的函数swap,将函数的参数定义成引用的形式: void swap(int &p1, int &p2) //此处函数的形参都是引用 ...