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个棋子 ...
随机推荐
- Unreal Engine 4 RenderTarget制作Live Camera效果
Unreal Engine 4 RenderTarget制作Live Camera效果 先上效果: Live Camera我不知道怎么翻译.反正意思就是将一个摄影机的Image渲染到一个2D平面上. ...
- HDU 1114 Piggy-Bank 全然背包
Piggy-Bank Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit S ...
- hdu2175汉诺塔IX
汉诺塔IX Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- SQL声明发育异常导致项目错误
1.错误叙述性说明 严重:Exception occurred during processing request:Statement Callback;SQL[ ];OALL8处于不一致状态; ...
- C语言 cgi(3)
1cs3157 – Advanced ProgrammingSummer 2014, Project 1, 150 pointsJune 17, 2014Follow these step-by-st ...
- malloc功能具体解释
一.原型:extern void *malloc(unsigned int num_bytes); 头文件:#include <malloc.h> 或 #include <alloc ...
- UVA11100- The Trip, 2007
option=com_onlinejudge&Itemid=8&category=512&page=show_problem&problem=2041"> ...
- Android源码及SDK国内镜像下载
Android源码及SDK国内镜像下载Android源码下载: 今天发现,清华大学提供AOSP镜像,以前都是从Google的站点下载同步更新的,但是现在有了国内的镜像站点就好多了,下载Androidd ...
- C# Windows Phone 8 WP8,切换各国语系免重开机 加速开发 送审有效率!!
原文:C# Windows Phone 8 WP8,切换各国语系免重开机 加速开发 送审有效率!! 一般我们在开发Windows Phone 8 时,会考虑到各国语言的问题,但是你有想过吗?用实体手机 ...
- python 凸包(经纬度) + 面积[近似]
def cross(A,B): return A[0] * B[1] - A[1] * B[0] def vectorMinus( a , b): return ( (a[0] - b[0] )*10 ...