Network Saboteur(搜索)
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 10351 | Accepted: 4968 |
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
题目大意:给定x个元素的图,将这些点集合分成两部分A,B,然后取A中所有元素到B中所有元素的权值之和,求最大值。
搜索出所有的情况然后取最大值。对搜索还不是熟悉,看的题解做的。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int map[][];
int n,Max,sum;
bool flag[];
int dfs(int x)
{
if(x==n)
{
sum=;
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(flag[i]&&!flag[j])
sum+=map[i][j];
if(sum>Max)
Max=sum;
return ;
}
else /*不断向下展开*/
{
flag[x]=;
dfs(x+);
flag[x]=;
dfs(x+);
}
return ;
}
int main()
{
int i,j,k;
while(cin>>n)
{
Max=;
for(i=;i<=n;i++)
for(j=;j<=n;j++)
cin>>map[i][j];
memset(flag,,sizeof(flag));
dfs();
cout<<Max<<endl;
}
}
Network Saboteur(搜索)的更多相关文章
- Network Saboteur 分类: 搜索 POJ 2015-08-09 19:48 7人阅读 评论(0) 收藏
Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10147 Accepted: 4849 Des ...
- poj2531 Network Saboteur
Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11122 Accepted: 5372 ...
- POJ2531——Network Saboteur(随机化算法水一发)
Network Saboteur DescriptionA university network is composed of N computers. System administrators g ...
- CSU-ACM2016暑假集训训练2-DFS(C - Network Saboteur)
C - Network Saboteur Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu ...
- Network Saboteur POJ 2531 回溯搜索
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 12886 Accepted: 6187 Description A un ...
- POJ-2561 Network Saboteur(DFS)
题目: A university network is composed of N computers. System administrators gathered information on t ...
- POJ 2531 Network Saboteur
http://poj.org/problem?id=2531 题意 :有N台电脑,每两台电脑之间都有个通信量C[i][j]; 问如何将其分成两个子网,能使得子网之间的通信量最大. 也就是说将所有节点分 ...
- Network Saboteur
poj2531:http://poj.org/problem?id=2531 题意:给你一个图,图中点之间会有边权,现在问题是把图分成两部分,使得两部分之间边权之和最大.题解:一开始比知道怎么办,想用 ...
- C——Network Saboteur (POJ2531)
题目: A university network is composed of N computers. System administrators gathered information on t ...
随机推荐
- 用jquery可以用使用serialize()序列化表单值,那有没有什么方法可以将值填充到表单中呢? (一段不错的代码)
serialize()的作用,是生成一个类似这种格式的字符串用于ajax提交 a=&b=&c=.你想将值填写到表单,首先要有值,然后就是表单控件的id或者能唯一定位控件的属性.然后就$ ...
- Block(二)内存管理与其他特性
一.block放在哪里 我们针对不同情况来讨论block的存放位置: 1.栈和堆 以下情况中的block位于堆中: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...
- 关于cookie, iphone及chrome的异同
http://www.blogjava.net/jjshcc/archive/2010/06/13/323517.html http://stackoverflow.com/questions/295 ...
- 《Programming WPF》翻译 第5章 4.元素类型样式
原文:<Programming WPF>翻译 第5章 4.元素类型样式 命名样式非常有用,当你得到一组属性并应用到特点的元素上.然而,如果你想要应用一个统一的样式到所有确定元素类型的实例, ...
- [置顶] Responder一点也不神秘————iOS用户响应者链完全剖析
这篇文章想跟大家分享的主旨是iOS捕获用户事件的各种情况,以及内部封装的一些特殊事件. 我们先从UIButton谈起,UIButton大家使用的太多了,他特殊的地方就在于其内置的普通Default/高 ...
- 网络版shell之网络编程练习篇--telnet服务端
网络版shell之网络编程练习篇--telnet服务端 以前写过一个shell命令解释器,对与shell命令解释器的执行流程有了清晰的认识,这段时间学习网络编程,至于网络编程的细节以及知识点,已经 ...
- c#实现文件拖放
1. 选择form窗口,在事件分别双击双击DragDrop和DragEnter private void Form1_DragDrop(object sender, DragEventArgs e) ...
- mysql C API 字符串玩转备份调优
- Linux CPU 亲和性
在Linux中,我们知道可以通过nice.renice命令改变进程的执行优先级,优先级高的进程优先执行,从而一定程度上保证重要任务的运行. 除了nice.renice外,可以通过CPU affinit ...
- PC-HTML5-搜索框
代码如下: <input type="text" placeholder="输入 回车搜索" autofocus x-webkit-speech>很 ...