Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 12886   Accepted: 6187

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

最初的想法是枚举每次选择分组的组员个数,但是后来想到可以统一化处理,所有结点考虑取和不取两种状态,递归求解,
这里注意求值操作要放在递归最后一层判定返回,因为前面的选择对最后结果有影响。
#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 回溯搜索的更多相关文章

  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. poj 2531 搜索剪枝

    Network Saboteur Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u ...

  3. Network Saboteur(搜索)

    Network Saboteur POJ2531 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10351   Accept ...

  4. poj2531 Network Saboteur

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

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

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

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

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

  7. POJ ---2531

    Network Saboteur Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8751   Accepted: 4070 ...

  8. POJ 2531 暴力深搜

    Network Saboteur Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13494   Accepted: 6543 ...

  9. POJ 2531 Network Saboteur

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

随机推荐

  1. [Apple开发者帐户帮助]八、管理档案(4)

    您可以编辑,下载或删除在开发人员帐户中创建的配置文件.例如,如果您撤消了证书或禁用了配置文件中包含的设备,请编辑配置文件.或重新置备的个人资料,如果因为你它是无效的功能的应用程式服务. 注意: Xco ...

  2. 【原创】Vue项目中各种功能的实现

    已完成: 后台的管理功能: 这里用的组件是 element-UI  ====> NavMenu ◆首先是排版 : <div class="manage-page fillcont ...

  3. Python/Django 下载Excel2007

    一.前提 上一篇,我写了下载Excel2003的博文,这里写下载Excel2007的博文的原因有三: 第一.Excel2003基本已经淘汰了 第二.Excel2003下载文件太大,不利于网络传输 第三 ...

  4. Map,Filter 和 Reduce

    Map会将一个函数映射到一个输入列表的所有元素上 map(function_to_apply, list_of_inputs) items = [1, 2, 3, 4, 5] squared = li ...

  5. mongoDB的基本用法

    一.MongoDB初识 什么是MongoDB MongoDB是一个基于分布式文件存储的数据库.由c++语言编写.旨在为web应用提供可扩展的高性能数据存储解决方案. MongoDB是一个介于关系数据库 ...

  6. day03_12/13/2016_bean的管理之初始化和销毁

  7. 关于onActivityResult方法不执行的问题汇总

    我们不生产代码, 只是大自然的搬运工.  首先致谢: https://blog.csdn.net/sbvfhp/article/details/26858441 场景描述: 在A activity(由 ...

  8. WEB开发模式浅析

    WEB技术随着互联网的崛起而崛起,又随着移动互联网的发展而呈现更加多样化的趋势. 黑暗时代:大约在2005年以前,所谓的WEB开发主要还是美工的活,HTML/CSS占主导,Dreamwaver做为页面 ...

  9. Android studio在使用过程中的问题总汇!

    使用android studio也有一段时间了,汇总了一下这段时间内遇到一些常见问题,希望能够帮助到大家! 一.字体大小问题 在android studio的使用过程中没有发现类似于Eclipse中的 ...

  10. 解决 The file will have its original line endings in your working directory

    首先出现这个问题主要原因是:我们从别人github地址上通过git clone下载下来,而又想git push到我们自己的github上,那么就会出现上面提示的错误信息 此时需要执行如下代码: git ...