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. Docker(九):Docker容器卷插件

    1.Convoy 1.1 安装 [root@MediaServer tmp]# tar xvf convoy.tar.gz convoy/ convoy/convoy-pdata_tools conv ...

  2. DOM&JavaScript示例&练习

    以下示例均为html文件,保存至本地就可直接用浏览器打开以查看效果\(^o^)/~ 练习一:设置新闻字体 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTM ...

  3. JavaScript简单入门(补充篇)

    本文是对上一篇 JavaScript简单入门 的一些细节补充. 一.全局变量和局部变量 在<script>标签内定义的变量是当前页面中的全局变量.即 <script>标签可以直 ...

  4. 搭建subversion 服务器,并自动部署项目

    1 subversion目录文件说明: *dav目录:是提供apache与mod_dav_svn使用的目录,让他们存储内部数据*db目录:就是所有版本控制的数据存放文件*hooks目录:放置hook脚 ...

  5. alpha rarefaction using qiime

    shannon菌群多样性指数 H=-∑(Pi)(㏑Pi) Pi=样品中属于第i种的个体的比例,如样品总个体数为N,第i种个体数为ni,则Pi=ni/N: 各种之间,个体分配越均匀,H值就越大.如果每一 ...

  6. 微信跳一跳辅助自动跳Python

    一.说明 此代码借鉴github一位大神所写,已经做了简化合并处理,如果能成功连上手机并运行,可以实现程序自动玩游戏,刷个1000+的分数轻轻松松 github源码地址 https://github. ...

  7. cobbler自动安装系统(Centos7.X)

    环境: [root@kickstart ~]# cat /etc/redhat-release CentOS Linux release (Core) [root@kickstart ~]# unam ...

  8. python3基础(二)

    loops循环语句 一 if语句,if语句配合else使用,可以没有else. 单分支if语句 age = input('Age:') password = '67' if age == passwo ...

  9. Oracle loop循环无法插入数据

    以下的测试基于scott用户下的emp表 首先用while循环进行测试,向emp表插入999条数据 declare i emp.empno; begin loop insert into emp(em ...

  10. windows服务管理操作

    服务程序是windows上重要的一类程序,它们虽然不与用户进行界面交互,但是它们对于系统有着重要的意义.windows上为了管理服务程序提供了一个特别的程序:服务控制管理程序,系统上关于服务控制管理的 ...