Network Saboteur POJ 2531 回溯搜索
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 12886 | Accepted: 6187 |
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 最初的想法是枚举每次选择分组的组员个数,但是后来想到可以统一化处理,所有结点考虑取和不取两种状态,递归求解,
这里注意求值操作要放在递归最后一层判定返回,因为前面的选择对最后结果有影响。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<fstream>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 23
#define INF 1000000009
/*
给一个邻接矩阵表示一个图,要求把这个图分为两个部分,让两个部分之间距离和最大
两个部分之间距离和最大,当两个元素属于同一集合的时候两者之间距离为0
*/
int g[MAXN][MAXN], n,ans,k;
bool been[MAXN]; void dfs(int cnt)//当前考虑节点数目
{
if (cnt == n)
{
int sum = ;
for (int i = ; i < n; i++)
{
if (been[i])
{
for (int j = ; j < n; j++)
{
if (!been[j])
sum += g[i][j];
}
}
}
ans = max(sum, ans);
return ;
}
been[cnt] = true;
dfs(cnt + );
been[cnt] = false;
dfs(cnt + );
} int main()
{
while (scanf("%d", &n) != EOF)
{
ans = -;
for (int i = ; i < n; i++)
for (int j = ; j < n; j++)
scanf("%d", &g[i][j]);
dfs();
printf("%d\n", ans);
}
}
Network Saboteur POJ 2531 回溯搜索的更多相关文章
- Network Saboteur 分类: 搜索 POJ 2015-08-09 19:48 7人阅读 评论(0) 收藏
Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10147 Accepted: 4849 Des ...
- poj 2531 搜索剪枝
Network Saboteur Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u ...
- Network Saboteur(搜索)
Network Saboteur POJ2531 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10351 Accept ...
- 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 ...
- POJ ---2531
Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8751 Accepted: 4070 ...
- POJ 2531 暴力深搜
Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13494 Accepted: 6543 ...
- POJ 2531 Network Saboteur
http://poj.org/problem?id=2531 题意 :有N台电脑,每两台电脑之间都有个通信量C[i][j]; 问如何将其分成两个子网,能使得子网之间的通信量最大. 也就是说将所有节点分 ...
随机推荐
- 使用display:flex;实现两栏布局和三栏布局
一.使用display:flex;实现两栏布局 body,div{margin:0px;padding:0px;} .flex-container{display:flex;height:300px; ...
- nodejs在windows下的安装
Windowv 上安装Node.js Windows 安装包(.msi) : 32 位安装包下载地址 : http://nodejs.org/dist/v0.10.26/node-v0.10.26-x ...
- [App Store Connect帮助]三、管理 App 和版本(6.2)转让 App:App 转让条件
App 必须满足以下条件才可转让: 转让者和接收者的帐户均不处于待处理或变更状态,且双方均已接受“协议.税务和银行业务”部分中最新版本的转让协议 该 App 的任何版本都不能使用 iCloud 权限 ...
- Oracle group by分组拼接字符串
select wm_concat(id),depon from test_1 group by depon
- DB2锁表或超时解决方案
DB2锁表或超时 一.场景 对数据表进行更新(查询没问题),错误提示如下: SQLCODE=-911, SQLSTATE=40001, DRIVER=3.63.75SQL0911N The curre ...
- ACM_栈的压入、弹出序列
栈的压入.弹出序列 Time Limit: 2000/1000ms (Java/Others) Problem Description: 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列 ...
- Raspberry Pi开发之旅-空气温湿度检测(DHT11)
一.首先,简单介绍下DHT11: DHT11是一个温湿度传感器,分为3个接口,分别为:VCC, DATA, GND 引脚号 名称 类型 说明 1 VCC 电源 +级,输入3V-5.5V 2 DATA ...
- cms判断写法
cms比较容易写出循环的网页内容,对于有些循环的网页内容有不同css设定,这样在写cms时需要对循环做出条件判断:{if 判断条件}输出内容{else}输出内容{/if}.通过判断可以实现图片轮播效果 ...
- 易语言 打开exe可执行文件、打开网页
打开文件--------按钮被单击事件 直接复制以下代码即可 .版本 2 .子程序 _按钮58_被单击 运行 (“exe文件路径”, 假, ) 打开网站--------按钮被单击事件 直接复制以下代码 ...
- java设计模式03装饰者者模式
动态地给一个对象添加一些额外的职责.就增加功能来说, Decorator模式相比生成子类更为灵活.该模式以对客 户端透明的方式扩展对象的功能. (1)在不影响其他对象的情况下,以动态.透明的方式给单个 ...