Network Saboteur POJ2531
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 10351   Accepted: 4968

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
题目大意:给定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(搜索)的更多相关文章

  1. Network Saboteur 分类: 搜索 POJ 2015-08-09 19:48 7人阅读 评论(0) 收藏

    Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10147 Accepted: 4849 Des ...

  2. poj2531 Network Saboteur

    Network Saboteur Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11122   Accepted: 5372 ...

  3. POJ2531——Network Saboteur(随机化算法水一发)

    Network Saboteur DescriptionA university network is composed of N computers. System administrators g ...

  4. CSU-ACM2016暑假集训训练2-DFS(C - Network Saboteur)

    C - Network Saboteur Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu ...

  5. Network Saboteur POJ 2531 回溯搜索

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12886   Accepted: 6187 Description A un ...

  6. POJ-2561 Network Saboteur(DFS)

    题目: A university network is composed of N computers. System administrators gathered information on t ...

  7. POJ 2531 Network Saboteur

    http://poj.org/problem?id=2531 题意 :有N台电脑,每两台电脑之间都有个通信量C[i][j]; 问如何将其分成两个子网,能使得子网之间的通信量最大. 也就是说将所有节点分 ...

  8. Network Saboteur

    poj2531:http://poj.org/problem?id=2531 题意:给你一个图,图中点之间会有边权,现在问题是把图分成两部分,使得两部分之间边权之和最大.题解:一开始比知道怎么办,想用 ...

  9. C——Network Saboteur (POJ2531)

    题目: A university network is composed of N computers. System administrators gathered information on t ...

随机推荐

  1. DataTables给每一列添加下拉框搜索

    $(document).ready(function() { $('#example').DataTable( { initComplete: function () { var api = this ...

  2. Jasper_dataSource_CSV data source config

    (1)    open eclipse Repository Explorer Window->Show View->Other-> Repository Explorer-> ...

  3. php----浅谈一下empty isset is_null的用处

    } }    {      }  {       } } }    {      }  {       } is_null():判断变量是否为null if ($a){} 那这个未声明变量会报noti ...

  4. oracle ed命令

    今天在弄oracle sqlplus的时候需要写一个存储过程,用ed进入之后,退不出来了. 从网上找到下面的方法处理:   如何退出sqlplus ed操作   今天进入sqlplus ,执行完语句后 ...

  5. 新版TeamTalk部署教程(蓝狐)

    http://www.bluefoxah.org/teamtalk/new_tt_deploy.html

  6. Qt自定义圆周动画(360 10.0 的模仿作者写的)

    由于项目需求,需要把一张图片做圆周运动,用到了属性动画,坐标计算等. 在编写代码的过程中,由于太长时间没用sin,cos函数忘了是用弧度为单位,汗呀 下面把代码贴出来 /* * 圆周运动动画 * */ ...

  7. EXTJS 4.2 实现 gridpanel 鼠标悬停单元格以提示信息的方式显示单元格内容。

    由于gridpanel的单元格里的文字太多时候,都由省略号代替,就想实现如题的功能,经过反复实验,终于搞定了!直接上代码: me.on('itemmouseenter', function (view ...

  8. Microsoft Certification List

    Exam Title Files 70-178 Microsoft Project 2010, Managing Projects 16 70-243 Administering and Deploy ...

  9. git:fatal the current branch master has no upstream branch

    git push的时候发生上述错误. git push -u "resp" master resp为git仓库的“地址” reference中由解决方案 http://blog.c ...

  10. mysql命令行的基本用法

    基础介绍:1.在linux下使用下列命令,请确认mysql的bin目录是否已经加入到PATH路径中,或者是已经进入到mysql安装路径下的bin目录查看PATHshell> echo $PATH ...