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个棋子 ...
随机推荐
- jconsole线程面板中的阻塞总数和等待总数(转)
阻塞总数 Blocked count is the total number of times that the thread blocked to enter or reenter a monito ...
- leetcode第一刷_Convert Sorted List to Binary Search Tree
好,二叉搜索树粉末登场,有关他的问题有这么几个,给你一个n,如何求全部的n个节点的二叉搜索树个数?能不能把全部的这些二叉搜索树打印出来? 这道题倒不用考虑这么多,直接转即可了,我用的思想是分治,每次找 ...
- flex4 amcharts 删除水印
package com.twobowl.component.manualTopo { import com.amcharts.AmPieChart; import com.amcharts.chart ...
- Vb.net/VB 声明API功能父窗口功能
回想第一次敲房费,他说自己是api函数实现父窗口及其子窗口最小化的功能.现在再次遇到,自己就在思考,能不能继续使用API函数呢?答案当然是Of Course! 事实上细致看两者并没有多大的差别,先看看 ...
- Activity详细解释(生命周期、以各种方式启动Activity、状态保存,等完全退出)
一.什么是Activity? 简单的说:Activity或者悬浮于其它窗体上的交互界面. 在一个应用程序中通常由多个Activity构成.都会在Manifest.xml中指定一个主的Activity, ...
- oracle转mysql总结(转)
ares-sdk初始开发测试使用的是oracle数据库,由于宁波通商的特殊需要,必须把数据库环境从oracle转向mysql. 现对转换过程中出现的问题及经验总结如下: 主键生成策略 创建一个专门记录 ...
- siwft初学(一)
今天刚開始学习swift语言.首先须要下载xcode6 beta版本号.正式版本号然后会公布.自己学习总结一下,假设有误.请大家指出. 创建project的时候.language选择swift语言. ...
- 【SICP归纳】2 高阶函数和数据抽象
上一篇博文相应的是书中的第一章的一二两节,我们已经大致的有了一种构造的感觉不是么. 书中展示了非常多有趣的句法(syntax). 如今我们要让思想进一步的抽象.写这篇博客的时候并未学完整本书.更不敢说 ...
- [Windwos Phone 8]多个按钮的共用事件
原文:[Windwos Phone 8]多个按钮的共用事件 前言 ------------------------------------------------------------------- ...
- php覆盖理解
我们经常听到的面向对象的三大特点:包裹.承受.多态,但是,还有很多功能,因此,我们记住它改写?在研究中,对下一个时一个简单的记录php中重写方法: 1)通过样品首先看,这更明显 <?php // ...