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

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

Source

Northeastern Europe 2002, Far-Eastern Subregion
一道poj搜索简单题。

题意如下:给定一个n*n的方阵描述一个无向带权图,试将改图点集拆分成两个集合使两个集合之间的权值最大。

思路如下:搜索要解决一下两个问题,第一是如何枚举点兵划分入两个集合,第二是如何剪枝优化。首先,要解决n个点的集合归属,直接暴力枚举,用子集枚举的位向量法即可;而对于第二个问题,这里需要一点逆向思维。求集合之间的权值最大,求的其实是每个集合内部那些不能统计的边权值要最小,这样就可以得到转化,答案=边权和-集合内边权和。所以,进行可行性剪枝:若已枚举了所有点,则记录最小值,回溯;同理,进行最优化剪枝:若当前累计边权大小已超过了历史最小值,就剪枝。

15781005

  ksq2013 2531 Accepted 664K 313MS G++ 754B 2016-07-22 11:29:51

代码如下:

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
bool sub[21];
int n,tot,minn=0x3f3f3f3f,w[21][21];
void dfs(int ind,int sum)
{
if(sum>minn)return;
if(ind>n){
minn=sum;
return;
}
int tmp=0;
sub[ind]=0;
for(int i=1;i<ind;i++)
if(!sub[i])
tmp+=w[ind][i];
dfs(ind+1,sum+tmp);
tmp=0;
sub[ind]=1;
for(int i=1;i<ind;i++)
if(sub[i])
tmp+=w[ind][i];
dfs(ind+1,sum+tmp);
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
scanf("%d",&w[i][j]);
tot+=w[i][j];
}
}
dfs(1,0);
printf("%d\n",tot/2-minn);
return 0;
}
/*
3
0 50 30
50 0 40
30 40 0
*/

poj2531 Network Saboteur的更多相关文章

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

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

  2. Network Saboteur(搜索)

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

  3. Network Saboteur 分类: 搜索 POJ 2015-08-09 19:48 7人阅读 评论(0) 收藏

    Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10147 Accepted: 4849 Des ...

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

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

  5. C——Network Saboteur (POJ2531)

    题目: A university network is composed of N computers. System administrators gathered information on t ...

  6. Network Saboteur(Rand版)

    poj2531:http://poj.org/problem?id=2531 题意:给你一个图,图中点之间会有边权,现在问题是把图分成两部分,使得两部分之间边权之和最大.题解:随机算法 #includ ...

  7. Network Saboteur

    poj2531:http://poj.org/problem?id=2531 题意:给你一个图,图中点之间会有边权,现在问题是把图分成两部分,使得两部分之间边权之和最大.题解:一开始比知道怎么办,想用 ...

  8. Network Saboteur (深搜递归思想的特殊使用)

    个人心得:对于深搜的使用还是不到位,对于递归的含义还是不太清楚!本来想着用深搜构成一个排列,然后从一到n分割成俩个数组,然后后面发现根本实现不了,思路太混乱.后来借鉴了网上的思想,发现用数组来标志,当 ...

  9. Network Saboteur POJ 2531 回溯搜索

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12886   Accepted: 6187 Description A un ...

随机推荐

  1. WCF服务配置编辑器使用

    学习wcf,特别是初学者,配置文件很难搞懂,有点复杂,自己手动配置哪有这么多精力啊,这不是吃的太饱了吗,所以学会使用配置编辑器是必须的,下面是学习的流程图. 打开工具的wcf服务配置编辑器,点击文件= ...

  2. LBS上传到百度地图

    准备: 第一步:注册百度地图开发者账号 第二步:使用开发者账号注册相对应秘钥 在LBS后台添加所需要上传的字段 1,添加WebClientHelper帮助类 2,LBS帮助类 private stri ...

  3. AFNetworking菊花转圈圈

    注意,此圈圈是在左上角,特别小,不注意是看不到的 加载这个东西,要先引入头文件: AFNetworkActivityIndicatorManager.h 然后只要一句代码就可以实现,默认情况下AFN的 ...

  4. array_filter、array_map、array_walk解释

    /** * array_filter 用回调函数处理数组中的各个元素, * 重点在于过滤(而不是新增)某个元素,当你处理到一个元素时, * 如果返回了false,那么这个元素将会被过滤掉.PS:保持了 ...

  5. 【转】Serverless架构

    这是来自martinfowler.com的Serverless架构一文的大意翻译. 什么是Serverless?    Serverless首先是用于描述我们的应用程序是明显或充分地依赖第三方应用或服 ...

  6. Scrum Master 面试题 – 你必须知道的22个Scrum基础知识

    以下的22个问题基本上涵盖了Scrum所涉及的内容,如果你能够正确回答出所有问题,那么你已经具备了作为一名Scrum Master的基本素质:当然,作为一名合格的Scrum Master,更重要的是你 ...

  7. 磁带机Media is unrecognized

    早晨检查磁带备份作业时,发现有个驱动的作业一直处于"Queue"状态,检查发现驱动有磁带,在Alert里面发现出现下面"Media is unrecognized&quo ...

  8. 点击jqGrid表格,弹出需要的表格的数据

    首先,我们先定义一个函数,然后在JQuery里面直接引用就可以了, function GetJqGridRowValue(jgrid, code) { var KeyValue = "&qu ...

  9. iOS极光推送,两次Bundleid不一致( 开发证书没有通过验证 是否重新上传证书)的解决方案

    极光在配置ios端推送时,需要上传p12证书,如果遇到如下图:: 证书上传未通过的原因一般有: 1.当前上传的p12证书密码输入有误: 2. 证书导出的时候展开了证书,把个人私钥导了出来,导证书的时候 ...

  10. day 2 Linux目录结构

    Linux系统的目录结构的基本介绍: 1)在逻辑上的所有目录(包括目录下的子目录)都在最高级别的目录“/”下. 根(/)目录是Linux系统中所有目录的起始点(顶点),根下面的目录及子目录是一个有层次 ...