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 ...
随机推荐
- logstash 字段类型转换后 需要刷新
filter { grok { match => [ "message" , "\s*%{IPORHOST:clientip}\s+\-\s+\-\s+\[%{HT ...
- 解决kibana 4 关于响应时间的问题
"message" => " 10.252.142.174 [12/Sep/2016:16:43:47 +0800] \"GET /resources/j ...
- 【转】win32,win64编程永恒;语言编程需要注意的64位和32机器的区别
原文网址:http://www.cnblogs.com/kex1n/archive/2010/10/06/1844737.html 一.数据类型特别是int相关的类型在不同位数机器的平台下长度不同.C ...
- JQuery轻量级网页编辑器 选中即可编辑
目前流行的可视化网页编辑器非常多,像ckeditor.kindeditor.tinyeditor等,虽然功能都非常强大,但是体积都比 较庞大,使用起来也不是很方便.今天我们分享一款基于jQuery的轻 ...
- 快速排序(Quick Sort)
快速排序是初学者比较难理解的几个算法之一,这里尽可简单化地讲解,希望能帮到大家. 快速排序基本步骤: 从数列中挑出一个元素,称为"基准"(pivot). 重新排序数列,所有元素比基 ...
- LVM(2)逻辑卷的扩展、缩减、快照卷
一.扩展逻辑卷:lvextend 扩展逻辑卷物理边界 -L [+]# /PATH/TO/LV2G, +3G5G
- Linux NFS服务器搭建
1.NFS:NFS(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源. 在NFS的应用中,本地N ...
- Function.prototype.call.apply结合用法
昨天在网上看到一个很有意思的js面试题,就跟同事讨论了下,发现刚开始很绕最后豁然开朗,明白过来之后发现还是挺简单的,跟大家分享下! 题目如下: var a = Function.prototype ...
- EffectiveC#9--明白几个相等运算之间的关系
1.当你创建你自己的类型时(不管是类还是结构),你要定义类型在什么情况下是相等的.C#提供了4个不同的方法来断定两个对象是否是相等的 public static bool ReferenceEqual ...
- BOM 窗体相关属性以及页面可见区域的获取方式
1 在IE Safari Oper Chrome 都提供了screenLeft和screenTop属性: screenLeft : 相对于屏幕左边的距离 screenTop : 相对于屏幕上边的距离 ...