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. JavaWeb学习笔记--Servlet代码集

    目录: 登录系统提交表单数据打开PDFCookieURL传递参数URL重写跟踪会话使用HttpSession对象跟踪会话Servlet间协作过滤器Filter 登录系统 <!DOCTYPE HT ...

  2. 单片微机原理P3:80C51外部拓展系统

    外部拓展其实是个相对来说很好玩的章节,可以真正开始用单片机写程序了,比较重要的是外部存储器拓展,81C55拓展,矩阵键盘,动态显示,DAC和ADC.   0. IO接口电路概念与存储器拓展 1. 为什 ...

  3. Blogger建立新文章 - Blog透视镜

    使用Blogger,建立好Blog部落格之后,接着就是建立新文章,它是Blog部落格的灵魂,先从简单开始,来了解建立新文章的标题,文章中如何上传图片,建立卷标,及设定排程日期,定时自动发布等这些功能, ...

  4. XJOI网上同步训练DAY1 T3

    思路:一开始看到这题的时候想DP,可是发现貌似不行..因为有前缀也有后缀,而且有的后缀会覆盖到现在的前缀,这就不满足无后效性了啊! 但是有个很巧妙的思路:如果我们知道a[i]的最大值,那么p的数量和q ...

  5. Qt修改文件内容

    在用Qt进行嵌入式开发的时候,有时需要通过界面永久的改变ip地址等网卡信息.此时只能修改系统中包含网卡信息的文件,下图红框中所示就是文件中的网卡信息. 那么如何修改这四行呢,我的做法是先打开该文本文件 ...

  6. PowerShell_零基础自学课程_9_高级主题:静态类和类的操作

    上次我们说到了,wmi对象和com组件,今天我们继续来看PS中对象的相关内容.主要说一下静态对象和对象的基本操作. 一.静态对象 在PS中有一类特殊的对象,我们不能同过这些类创建新的对象,这些类是不能 ...

  7. Min and Max

    Min and Max 需要处理不同数据类型; 另外*args, 表示的是位置参数, *kwargs表示的是key参数, args的类型为tuple类型, 参数为min(3, 2)时, args为(3 ...

  8. Java学习系列(一)Java的运行机制、JDK的安装配置及常用命令详解

    俗话说:“十五的月亮十六圆”.那学习是不是也是如此呢?如果把月亮看成是我们的愿望,那十五便是我们所处的“高原期”,坚持迈过这个坎,我相信你的愿望终究会现实的.记得马云曾说:今天很残酷,明天更残酷,后天 ...

  9. 通过Excel来集中管理资源文件

     在支持双语或多语种项目中,常常需要编辑多个文件来添加资源项,感觉比较繁琐,所以想做一个可以集中管理资源文件的工具.借助Excel,使用Excel来记录,并且通过Excel可以进行分页分模块来规划 ...

  10. LeetCode C++ 解题报告

    自己做得LeetCode的题解,使用C++语言. 说明:大多数自己做得,部分参考别人的思路,仅供参考; GitHub地址:https://github.com/amazingyyc/The-Solut ...