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

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
抄自 http://blog.csdn.net/martin31hao/article/details/8098302

题目大意:有n个点,把这些点分别放到两个集合里,在两个集合的每个点之间都会有权值,求可能形成的最大权值。

思路:1、把这两个集合标记为0和1,先默认所有点都在集合0里。

2、依次枚举每个点id,把每个点都放到集合1里去,这个时候就要调整集合的权值了,原来和id都在集合0里的点,要把权值加上;而在集合1里的点,要把权值减去。

3、权值调整完毕后,和ans比较,如果比ans要大, 调整ans。

4、如果放到集合1中,调整节点后的权值比放在集合0中要大,那么就默认这个点在集合1中,继续枚举下面的点进行DFS。最终是可以把最有状态都枚举出来的。

AC代码

 #include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#define maxn 100005
#define maxm 50000
using namespace std;
typedef long long ll;
int g[],a[][];
int ans,n;
void dfs(int k,int temp)
{
g[k]=;
int t=temp;
for(int i=;i<=n;i++)
{
if(g[i]==)
t-=a[k][i];
else
t+=a[k][i];
}
if(t>ans)
ans=t;
for(int i=k+;i<=n;i++)
{
if(t>temp)
{
dfs(i,t);
g[i]=;
}
}
}
int main(int argc, char const *argv[])
{
while(scanf("%d",&n)!=EOF)
{
memset(g,,sizeof(g));
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
cin>>a[i][j];
}
}
ans=;
dfs(,);
cout<<ans<<endl;
}
return ;
}

这题貌似最大割

POJ 2531 暴力深搜的更多相关文章

  1. bzoj 1024 暴力深搜

    我们直接暴力的深搜怎么切就行了, 每一刀切的方案只有横着和竖着,横竖又分在几等分点切, 因为要保证每个人的面积相同,所以比较好处理了,第几个几等分点就 分给这边几刀. /*************** ...

  2. POJ 1945 暴搜+打表 (Or 暴搜+判重)

    思路: 呃呃 暴搜+打表 暴搜的程序::稳稳的TLE+MLE (但是我们可以用来打表) 然后我们就可以打表过了 hiahiahia 可以证明最小的那个数不会超过200(怎么证明的我也不知道),然后就直 ...

  3. POJ 1414 暴搜

    题意比较复杂 (但是很好理解) 大概意思是给你等边三角形(详见题目中的图). 最后一行有n个数,下一次要填的数是c. 里面预先已经填好了数字.(0为未填) 得分的标准是这个分数的连通块周围没有空的地方 ...

  4. POJ 3188暴搜

    题意: 思路: 裸的暴搜 --. 但是要注意如果你不用所有的按键就能输出最优解的话一定要把所有的字母都安排到一个位置-. 我的一群PE就是这么来的-- 为什么写的人这么少-- // by Sirius ...

  5. POJ 2132 暴搜OR Floyd

    题意: 给你一个邻接矩阵(n<=25)问所有1到2路径的gcd的lcm是多少. 一些经验(WA/TLE的经验): 1. 无脑暴搜 是会TLE的--. 2. 关于精度 dyf神牛说了:long l ...

  6. POJ 2133 暴搜

    题意: 思路: 按照题意暴搜 注意 如果目标串==给的串 答案是2 //By SiriurRen #include <cstdio> #include <cstring> #i ...

  7. POJ - 2676 暴搜 注意实现细节

    经典sudoku问题 按部就班就好 一定要注意细节 大于1还是大于等于1 r c越界判断 judge时0的特判 blabla居然磨了2个小时 改了很多地方所以实现得有点冗余,反正能A吧 /*H E A ...

  8. POJ 2531 深搜剪枝

    题意:全局最大割. 分析:有相应的算法,数据量很小,可以枚举源点,汇点,最大流. 这里用DFS,状态定义:分成两个集合,刚开始S集合全部点,然后一个一个放,这是一个回溯的过程. 没剪枝也过了. 剪枝技 ...

  9. POJ 1543 暴搜

    题意:输出a^3=b^3+c^3+d^3的所有a,b,c,d的值. b,c,d由小到大且b,c,d都大于1. 思路: 按照题意写就好.... // by SiriusRen #include < ...

随机推荐

  1. 谷歌浏览器插件-jsonView插件安装与使用

    本文转载:http://www.bubuko.com/infodetail-700647.html 1 安装 1.打开 https://github.com : 2.搜索 jsonView 链接:ht ...

  2. c#中treeview的使用方法(转 )

    本文主要介绍treeView控件中,添加,修改.删除节点的操作, 首先当窗体加载的时候,我们添加上图中所示的节点. 当点击“Delete the Selected”按钮时,被选中的节点将被删除. 当点 ...

  3. 如何在markdown中插入表情

    Markdown是很好用的呀,个人灰常的喜欢,也是灰常漂亮的,但是如何在写文章的时候插入表情呢,下面给出一部分代码

  4. NP完整性| 集1(简介)

    我们一直在写关于高效算法来解决复杂问题,如最短路径,欧拉图,最小生成树等.这些都是算法设计者的成功故事. 在这篇文章中,讨论了计算机科学的失败故事. 计算机可以解决所有的计算问题吗? 存在计算问题,即 ...

  5. bzoj 4566: [Haoi2016]找相同字符

    Description 给定两个字符串,求出在两个字符串中各取出一个子串使得这两个子串相同的方案数.两个方案不同当且仅当这两 个子串中有一个位置不同. Input 两行,两个字符串s1,s2,长度分别 ...

  6. 修改Linux内核参数提高Nginx服务器并发性能

    当linux下Nginx达到并发数很高,TCP TIME_WAIT套接字数量经常达到两.三万,这样服务器很容易被拖死.事实上,我们可以简单的通过修改Linux内核参数,可以减少Nginx服务器 的TI ...

  7. 原生JavaScript实现一个简单的todo-list

    直接上代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  8. 随便说说 post-processing

    九月份一篇博都没更新,这段时间一直在unity的坑里爬不起来,感觉真的很绝望啊,仿佛对生活都失去了信心. 渲染问题并没有解决,目前方案只是减轻视觉冲突,降低违和感.项目AR产品也做的越来越艰难,开始经 ...

  9. Sublime Text 使用教程

    Sublime Text 是一款非常轻量级而且功能十分强大的编辑器,支持大量插件,深受前端开发者的喜爱.多的不说,我们直接进入正题. 1.下载 ①.官网下载地址:http://www.sublimet ...

  10. Python 为何能坐稳 AI 时代头牌语言

    原文链接:https://mp.weixin.qq.com/s?__biz=MzI0ODcxODk5OA==&mid=2247487055&idx=2&sn=ca0fe8740 ...