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]; 问如何将其分成两个子网,能使得子网之间的通信量最大. 也就是说将所有节点分 ...
随机推荐
- 父页面调用子页面js的方法
iframe子页面调用父页面javascript函数的方法今天遇到一个iframe子页面调用父页面js函数的需求,解决起来很简单,但是在chrome浏览器遇到一点小问题.顺便写一下iframe的父页面 ...
- codevs地鼠游戏(贪心)
1052 地鼠游戏 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 王钢是一名学习成绩优异的学生,在平时的学习中,他 ...
- Akka源码分析-Remote-ActorSystem
前面的文章都是基于local模式分析的,现在我们简要分析一下在remote模式下,ActorSystem的创建过程. final val ProviderClass: String = setup.g ...
- sigar的使用
与普通jar包不同,Sigar API还要依赖本地的库文件来进行工作,其中: Windows下Sigar.jar 依赖:sigar-amd64-winnt.dll 或 sigar-x86-winnt. ...
- ACM_圆的面积
圆的面积 Time Limit: 2000/1000ms (Java/Others) Problem Description: AB是圆O的一条直径,CD.EF是两条垂直于AB的弦,并且以CD为直径的 ...
- Spark 概念学习系列之Spark基本概念和模型(十八)
打好基础,别小瞧它! spark的运行模式多种多样,在单机上既可以本地模式运行,也可以伪分布模式运行.而当以分布式的方式在集群中运行时.底层的资源调度可以使用Mesos或者Yarn,也可使用spark ...
- semantic、vue 使用分页组件和日历插件
最近正在试试semantic-ui,结合了vue,这里忍不住吐槽semantic和vue的友好度简直不忍直视,不过既然用了,这里就分享几个用到的插件了 1.分页组件(基于vue) var pageCo ...
- C#用Microsoft.Office.Interop.Word进行Word转PDF的问题
之前用Aspose.Word进行Word转PDF发现'\'这个字符会被转换成'¥'这样的错误,没办法只能换个方法了.下面是Microsoft.Office.Interop.Word转PDF的方法: p ...
- java 任意时间转换日期类型
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); try { Date dd=sdf.parse("201 ...
- JS——scroll动画
固定导航栏 1.计算导航栏到顶部的距离值 2.当scrollTop值大于这个距离值就添加定位,当小于距离值后解除定位 注意事项:当导航栏添加定位之后,导航栏就脱离了文档流,也就是不占位了,下面的盒子就 ...