Network Saboteur
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 10391   Accepted: 4990

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
题意:将n个数分成两个集合,求一个集合中所有数到另一个集合所有数的最大和
 #include <iostream>
#include <cstring>
#include <string.h>
#include <algorithm>
#include <cstdio> using namespace std;
const int MAX = ;
int a[MAX][MAX],v[MAX],b[MAX];
int n,cnt,sum;
void dfs(int x,int sum)
{
v[x] = ;
for(int i = ; i <= n; i++)
{
if(v[i] == )
sum += a[x][i];
else
sum -= a[x][i];
}
cnt = max(cnt,sum);
for(int i = x + ; i <= n; i++) // 这个注意;其实可以这么想,以前求的是路径所以颠倒顺序也是一种情况,这是集合,所以颠倒顺序和原来是一种情况,所以没必要从0开始循环,0,1和1,0是一种情况
{
dfs(i,sum);
v[i] = ;
}
}
int main()
{
while(scanf("%d", &n) != EOF)
{
for(int i = ; i <= n; i++)
{
for(int j = ; j <= n; j++)
{
scanf("%d", &a[i][j]);
}
}
memset(v,,sizeof(v));
cnt = ;
dfs(,);
printf("%d\n",cnt);
}
return ;
}

POJ2531Network Saboteur(DFS+剪枝)的更多相关文章

  1. PKU 2531 Network Saboteur(dfs+剪枝||随机化算法)

    题目大意:原题链接 给定n个节点,任意两个节点之间有权值,把这n个节点分成A,B两个集合,使得A集合中的每一节点与B集合中的每一节点两两结合(即有|A|*|B|种结合方式)权值之和最大. 标记:A集合 ...

  2. *HDU1455 DFS剪枝

    Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  3. POJ 3009 DFS+剪枝

    POJ3009 DFS+剪枝 原题: Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16280 Acce ...

  4. poj 1724:ROADS(DFS + 剪枝)

    ROADS Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10777   Accepted: 3961 Descriptio ...

  5. DFS(剪枝) POJ 1011 Sticks

    题目传送门 /* 题意:若干小木棍,是由多条相同长度的长木棍分割而成,问最小的原来长木棍的长度: DFS剪枝:剪枝搜索的好题!TLE好几次,终于剪枝完全! 剪枝主要在4和5:4 相同长度的木棍不再搜索 ...

  6. DFS+剪枝 HDOJ 5323 Solve this interesting problem

    题目传送门 /* 题意:告诉一个区间[L,R],问根节点的n是多少 DFS+剪枝:父亲节点有四种情况:[l, r + len],[l, r + len - 1],[l - len, r],[l - l ...

  7. HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)

    Counting Cliques Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  8. HDU 5937 Equation 【DFS+剪枝】 (2016年中国大学生程序设计竞赛(杭州))

    Equation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  9. LA 6476 Outpost Navigation (DFS+剪枝)

    题目链接 Solution DFS+剪枝 对于一个走过点k,如果有必要再走一次,那么一定是走过k后在k点的最大弹药数增加了.否则一定没有必要再走. 记录经过每个点的最大弹药数,对dfs进行剪枝. #i ...

随机推荐

  1. JS 浮点数运算丢失精度解决方案

    除法 function accDiv(arg1,arg2){ var t1=0,t2=0,r1,r2; try{t1=arg1.toString().split(".")[1].l ...

  2. SEO在网页制作中的应用

    1.什么是SEOSEO(Search Engine Optimization)中文意译为“搜索引擎优化”.SEO是指通过网站内部调整优化及站外优化,使网站满足搜索引擎收录排名需求,在搜索引擎中提高关键 ...

  3. Restful是什么,SOAP Webservice和RESTful Webservice

    首先,应该怀着这样一种心态来学习Restful——Restful你可以将其理解一种软件架构风格,并且诠释了Http协议的设计初衷,所以不要把他理解的那么神秘,Restful风格有好处,当然也是有坏处的 ...

  4. 自动化测试: sikuli,一个基于界面图像的gui测试框架

    http://www.sikuli.org/ license: MIT script language: Python 下面是他的一个hello world的例子,看看也挺有意思的. 开源的世界里有很 ...

  5. 20135316王剑桥 linux第二周课实验笔记

    Linux中命令格式为: command [options选项] [arguments参数] //中括号代表是可选的,即有些命令不需要选项也不需要参数 ls或ls .显示是当前目录的内容,这里“.”就 ...

  6. swift第一季基础语法

    同: 一.基础 同: 1常量和变量 2数据类型和数据类型转换 3别名 不同: 1可选类型optional 2BOOL类型 3元组类型 4断言Assertion 二.基本操作符 同: 1赋值和算术运算及 ...

  7. wen7安装oracle 11g出现"未找到文件 E:\development_tools\database\oracle\install_d\dbhome\owb\external\oc4j_applications\applications\WFMLRSVCApp.ear"

    从oracle官网上下载了window7 64位的oracle安装包win64_11gR2_database_1of2,安装后出现了错误: 解决方法:继续下载oracle官网上的文件2:win64_1 ...

  8. unity3d 依赖关系获取预制件任意资源

    前段时间策划们想知道UI预制件中使用了哪些音效 N多预制件.N多音效!! 如果纯人工整理的话这还不累成狗? 累成狗不说,还容易出错 所以获取音频剪辑小工具就诞生了,将策划从死亡边缘拉了回来 我们先看一 ...

  9. xsd、wsdl生成C#类的命令行工具使用方法

    1.xsd生成C#类命令 示例:xsd <xsd文件路径> /c /o:<生成CS文件目录> <其他参数> 参数说明: /c 生成为cs文件,/d 生成DataSe ...

  10. .net,微软,薪资及其他

    很久没在博客园上写些东西,因为我的确没有什么技术上面新奇的心得和大家分享,园子里面的文章页没啥看的,基本就是看一下业界新闻,因为这里面99%的东西没什么看头,更像是个人技术笔记汇总. 我从07年从de ...