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]; 问如何将其分成两个子网,能使得子网之间的通信量最大. 也就是说将所有节点分 ...
随机推荐
- codevs 2541 幂运算(迭代加深搜索)
2541 幂运算 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 从m开始,我们只需要6次运算就可以计算出m31 ...
- HTML--使用mailto在网页中链接Email地址
<a>标签还有一个作用是可以链接Email地址,使用mailto能让访问者便捷向网站管理者发送电子邮件.我们还可以利用mailto做许多其它事情.下面一一进行讲解,请看详细图示: 注意:如 ...
- Centos7基本命令
shell基本命令 linux命令行的组成结构 linux系统命令操作语法格式 命令 空格 参数 空格 文件路径或者需要处理的内容 rm -rf /tmp/* ls -la /home ...
- 关于将电脑背景+chrome等网页改成护眼豆沙绿
常用电脑的人都知道,白色等其他对比度大的颜色对眼伤害大,所以需换成柔和的豆沙绿,可长时间保证眼睛的不疲劳 windows浏览器: >>>>在桌面点右键,依次选属性(proper ...
- TensorFlow-Gpu环境搭建——Win10+ Python+Anaconda+cuda
参考:http://blog.csdn.net/sb19931201/article/details/53648615 https://segmentfault.com/a/1190000009803 ...
- jQuery——jQuery选择器
基本选择器 # Id选择器 $(“#btnShow”)选择id为btnShow的一个元素 . 类选择器 $(“.liItem”)选择含有类liItem的所有元素 ele 标签选择器 $(“li”)选择 ...
- JS——事件的绑定与解绑
1.绑定形式 ele.addEventListener(evtName, fn) ele["on" + evtName] = function () {} ele.onclick ...
- 【译】x86程序员手册11- 4.1系统寄存器
4.1 Systems Registers 系统寄存器 The registers designed for use by systems programmers fall into these cl ...
- 贴一段自动编译java,并混淆编译的代码
刚写的一个自动编译.混淆.打包jar的代码,做个记录 用到的NuGet: <?xml version="1.0" encoding="utf-8"?> ...
- vmware vSphere client中,选择文件->部署OVF模板,报错处理方法
在vmware vSphere client中,选择文件->部署OVF模板,选择指定的OVA文件,按步骤进行,则会出现这样的错误:此OVF软件包使用了不受支持的功能.OVF软件包需要不支持的硬件 ...