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 修改AD密码

    sharepoint 修改AD密码 下面是添加添加“空元素”代码: 第一个<CustomAction>是添加修改密码项目 第二个<CustomAction>是添加js修改脚本 ...

  2. 转:jQuery.data

    原文地址:http://www.it165.net/pro/html/201404/11922.html 内存泄露 首先看看什么是内存泄露,这里直接拿来Aaron中的这部分来说明什么是内存泄露,内存泄 ...

  3. Swift使用注意

    二.函数的可选参数 参数名:参数类型? = 默认值 // 调用的时候会发现生成了两个函数,一个带imageName,一个不带,选择不带的,调用此函数时将使用参数值nil convenience ini ...

  4. Android忘记密码功能实现

    连续好几天学习都没有什么进展,然而在今天这个烂漫的日子.突然有了学习的动力.想起来前几日老师给布置的android忘记密码的功能实现.今天也有了想法.就是按照老师的建议,简单的回答一个问题,实现此功能 ...

  5. No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCHS=i386)

    今天在运行一个老ios项目的时候,突然报错:No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VAL ...

  6. 优化MySchool数据库(事务、视图、索引)

    事务.视图.索引: 事务:当生活逻辑中的“一个步骤”,需要使用多条SQL去完成时,必须使用事务来确保其“完整性“. 视图:简化数据库结构,方便你编写SQL语句(简化SQL语句的编写) 索引:提高“数据 ...

  7. 【读书笔记】iOS网络-解析响应负载

    Web Service可以通过多种格式返回结构化数据, 不过大多数时候使用的是XML与JSON.也可以让应用只接收HTML结构的数据.实现了这些Web Service或是接收HTML文档的应用必须能解 ...

  8. WPF 使用Caliburn.Micro 多线程打开窗口

    我们都知道在WPF里面用多线程打开一个窗口很简单.如下 public void ClickMe(object sender) { Thread newWindowThread = new Thread ...

  9. PNote桌面贴小工具 - 项目管理系列文章

    项目经理在项目过程中将会使用到各种工具,以期能够相互配合,对项目组的各种管理工作进行工作的开展和完成.以前就写过一些项目工具的使用,见下链接: 1.Mindjet MindManager思维导图工具的 ...

  10. 9、数据库工程师要阅读的书籍 - IT软件人员书籍系列文章

    数据库设计是软件项目底层的工作,它关系到软件项目的基础内容设计问题.数据库工程师的工作,就是设计数据库,维护数据库,优化数据库,这个跟DBA数据库助手的工作类似.现在的数据库有好几种了,比如MS SQ ...