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. SharePoint 2013 使用 PowerShell 更新用户

    在SharePoint开发中,经常会遇到网站部署,然而,当我们从开发环境,部署到正式环境以后,尤其是备份还原,所有用户组的用户,还依然是开发环境的,这时,我们就需要用PowerShell更新一下: P ...

  2. Linux下EclipseCDT工程和TFS的持续集成CI实践

    在Linux下使用TFS自动构建,需要自动执行连接tfs服务器的操作,命令行文件包TEE-CLC-10.1.0.2011121402.zip,下载地址:http://www.microsoft.com ...

  3. linux heartbeat v2/v3 的一点资料

    http://linux-ha.org http://linux-ha.org/wiki/Pacemaker Heartbeat2 http://blog.taggesell.de/index.php ...

  4. 【C语言】C语言标识符

    目录: [定义]  [作用]  [命名规则]  [命名规范] 1.定义  标识符就是我们给函数或变量定义的名称.方便查阅增强可读性.减少沟通成本. 2.作用  · 增强可读性.  · 减少沟通成本. ...

  5. 如何优化TableView

    关于UITable的优化: 1.最常用的就是不重复生成单元格,很常见,很实用: 2.使用不透明的视图可以提高渲染速度,xCode中默认TableCell的背景就是不透明的: 3.如果有必要减少视图中的 ...

  6. C语言中的字符串

    字符串 字符串 用双引号引起来的多个字符. 在C语言中字符串是用’\0’结束的.即每个字符串的最后一个字符是’\0’,但是结束符不显示,仅仅标志该字符串到这儿就结束了. 二.声明字符串 char *s ...

  7. 1.3 基础知识——GP2.1 方针(Policy)

    摘要: 方针这个GP每个PA都有,其实CMMI实践有没有实在价值,就在于方针!如果我们做出来的CMMI实践仅仅就是写文档.多步骤.没事找事,那其实就是违背了公司的商业目标,公司的商业目标简单说就是:用 ...

  8. MapReduce实例-倒排索引

    环境: Hadoop1.x,CentOS6.5,三台虚拟机搭建的模拟分布式环境 数据:任意数量.格式的文本文件(我用的四个.java代码文件) 方案目标: 根据提供的文本文件,提取出每个单词在哪个文件 ...

  9. SQLServer中给表增加组合唯一约束

    将两个或者多个字段一起约束成一个唯一约束 alter table 表名 add constraint 约束名 unique (列名1,列名2)

  10. sql server 警报管理,实时监听数据库动向,运筹帷幄之中

    工作这么多年了,无论是身边的同学还是同事,发现只要搞程序员的都有一个通病---懒.懒到谁都不愿意加班,尤其是"义务"加班.即使大家都不愿意加班,但是很多时候项目赶着上线或者上线之后 ...