POJ 2531-Network Saboteur(DFS)
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 9435 | Accepted: 4458 |
Description
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
Output file must contain a single integer -- the maximum traffic between the subnetworks.
Output
Sample Input
3
0 50 30
50 0 40
30 40 0
Sample Output
90
题意 :给出n个点和他们之间的权值Cij。如今要将n个点分为两部分,求∑Cij (i∈A,j∈B)最大
思路:dfs暴搜
算是没剪枝吧。。跑了219MS sad
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cctype>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define ll long long
#define maxn 360
#define pp pair<int,int>
#define INF 0x3f3f3f3f
#define max(x,y) ( ((x) > (y)) ? (x) : (y) )
#define min(x,y) ( ((x) > (y)) ? (y) : (x) )
using namespace std;
int ma[23][23],n,ans;
bool vis[23];
void dfs(int x,int num,int sum)
{ if(num>n/2+1)return ;
int t=0;
ans=max(ans,sum);
for(int i=x+1;i<=n;i++)
{
if(!vis[i])
{
vis[i]=1;
int tem=sum;
for(int j=1;j<=n;j++)
if(vis[j])
tem-=ma[i][j];
else
tem+=ma[i][j];
dfs(i,num+1,tem);
vis[i]=0;
}
}
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
scanf("%d",&ma[i][j]);
memset(vis,0,sizeof(vis));
ans=-INF;
dfs(0,0,0);
printf("%d\n",ans);
}
return 0;
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
POJ 2531-Network Saboteur(DFS)的更多相关文章
- poj 2531 Network Saboteur( dfs )
题目:http://poj.org/problem?id=2531 题意:一个矩阵,分成两个集合,求最大的 阻碍量 改的 一位大神的代码,比较简洁 #include<stdio.h> #i ...
- poj 2531 Network Saboteur(经典dfs)
题目大意:有n个点,把这些点分别放到两个集合里,在两个集合的每个点之间都会有权值,求可能形成的最大权值. 思路:1.把这两个集合标记为0和1,先默认所有点都在集合0里. 2 ...
- POJ 2531 Network Saboteur (枚举+剪枝)
题意:给你一个图,图中点之间会有边权,现在问题是把图分成两部分,使得两部分之间边权之和最大. 目前我所知道的有四种做法: 方法一:状态压缩 #include <iostream> #inc ...
- Network Saboteur (DFS)
题目: A university network is composed of N computers. System administrators gathered information on t ...
- poj 2531 Network Saboteur 解题报告
题目链接:http://poj.org/problem?id=2531 题目意思:将 n 个点分成两个部分A和B(也就是两个子集啦), 使得子集和最大(一定很难理解吧,呵呵).举个例子吧,对于样例,最 ...
- Network Saboteur(搜索)
Network Saboteur POJ2531 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10351 Accept ...
- POJ 3009-Curling 2.0(DFS)
Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12158 Accepted: 5125 Desc ...
- C——Network Saboteur (POJ2531)
题目: A university network is composed of N computers. System administrators gathered information on t ...
- 题解报告:poj 1321 棋盘问题(dfs)
Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子 ...
随机推荐
- 有关信息ACM/ICPC竞争环境GCC/G++叠插件研究记录的扩展
0.起因 有时.DFS总是比BFS受人喜爱--毕竟DFS简单粗暴,更,而有些东西BFS不要启动,DFS它似乎是一个可行的选择-- 但是有一个问题,DFS默认直接写入到系统堆栈.系统堆栈和足够浅,此时O ...
- LeetCode: Best Time to Buy and Sell Stock III [123]
[称号] Say you have an array for which the ith element is the price of a given stock on day i. Design ...
- 《JavaScript设计模式与开发实践》读书笔记之中介者模式
1. 中介者模式 中介者模式的作用就是用来解除对象与对象之间的紧耦合关系,增加中介者后,所有相关对象都通过中介者来通信,而不再相互引用 1.1中介者模式的例子 以泡泡堂游戏为例,先定义一个玩家构造函数 ...
- Web监听器导图详解(转)
阅读目录 Web监听器 监听器的分类 Servlet版本与Tomcat版本 getAttribute与getParameter的区别 参考 监听器是JAVA Web开发中很重要的内容,其中涉及到的知识 ...
- 王立平--Program Files (x86)
window7根据系统.program files(x86) 它是应用程序目录,在64下位系统.为了更好的相容性32位程序,在一些安装32位程序(请注意,有些节目自己是32位),将默认被安装progr ...
- 内网port映射具体解释(花生壳)
关于怎样建立服务器的解答. 一.花生壳的作用 首先,我们先来了解一下花生壳的究竟有什么作用.由于ADSL每次拨号上网所获得的IP地址每次都是不同的,花生壳起到的作用就是方便用户訪问我们的server( ...
- C# Windows Phone 8 WP8 高级开发,制作不循环 Pivot ,图片(Gallery)导览不求人! 内附图文教学!!
原文:C# Windows Phone 8 WP8 高级开发,制作不循环 Pivot ,图片(Gallery)导览不求人! 内附图文教学!! 一般我们在开发Winodws Phone APP 的时候往 ...
- ODAC配置
1.安装Oracle11g服务端 2.安装ODAC ODTwithODAC121012 3.拷贝Oracle11g服务端: F:\app\adccTest\pro ...
- Windows Server 2012 R2在桌面上显示计算机/网络图标
原文 Windows Server 2012 R2在桌面上显示计算机/网络图标 从Windows2012开始,微软取消了服务器桌面个性化选项,如何重新调出配置界面,可以使用微软命令调出.具体方法如下: ...
- 【原创】纯OO:从设计到编码写一个FlappyBird (四)
第三部分请点这里 这里来实现Obstacle类.其实flappybird的本质就是小鸟原地掉,然后几根柱子在走.这也是在Game类里,用obs.move()来实现游戏逻辑的原因. 我们首先必须确定几个 ...