POJ 2531 Network Saboteur 【DFS】

【POJ2531】Network Saboteur(一道无需优化的DFS) 题面:【POJ2531】Network Saboteur 可以说,这道题是一道无需优化的DFS,由于N最大只有20,连O(2^n)的复杂度都能过,因此,只需要DFS枚举每一个节点分配到哪一个子集即可。 因此就能得出代码: #include<cstdio> #include<algorithm> #include<iostream> #include&lt... 阅读详情

 

 

Network Saboteur

Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 10084 Accepted: 4819

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

Source

Northeastern Europe 2002, Far-Eastern Subregion

 

 

 

题意: 这题是我做过的最难理解的一道题,我把题意讲一下,估计大家都会做了,如下:

假设有 4 台电脑,则有 1,2,3.4; 在这4台电脑中拿 n 个电脑方进 A中,其他的放在B中,A中的电脑不能有连接,B内的电脑也不能有连接,要算的就是A中的每一个电脑与B中的每一个电脑连接,算这些连接的总流量,如何划成两部分使得值最大;

假设 A { 1 , 2 ,3 } ,B { 4 } ;那么要算的就是 【1,4】,【2,4 】,【3,4】;当然,可能的划分不止这种,找出划分的值最大的方案,然后输出那个值;

 

 

#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<time.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<list>
#include<queue>
#include<map>

#define E exp(1)
#define PI acos(-1)
#define mod (ll)(1e9+9)
#define INF 0x3f3f3f3f;
#define MAX 40000
#define compare 0.00000001
#define exps 1e-8

//#define _CRT_SECURE_NO_WARNINGS
//#define LOCAL
using namespace std;

typedef long long ll;
typedef long double lb;

int a[22][22], res, n, book[22];

void dfs(int sum,int cur,int last) {
	int tmp = sum;
	
	for(int i = 0 ; i < n ; ++i) {
		if(cur == -1) break;
		if(book[i] == 0) tmp+=a[cur][i];
		else {
			if(last > -1)
			tmp-=a[i][cur]; // 与上面的正好相反 cur & i 
		}	
	}
	if(res < tmp) res = tmp;
	
	for(int i = cur + 1; i < n ; ++i) {
		book[i] = 1;
		dfs(tmp,i,cur);
		book[i] = 0;
	} 
	return ;
}


int main(void)
{
#ifdef LOCAL
	freopen("data.in.txt", "r", stdin);
	freopen("data.out.txt", "w", stdout);
#endif
	//ios::sync_with_stdio(false); cin.tie(0);
	while (scanf("%d",&n) != EOF) {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				scanf("%d", &a[i][j]);
			}
		}
		memset(book,0,sizeof(book));
		res = 0;
		dfs(0,-1,-1);
		printf("%d\n", res);
	}
	//	end = clock();
	//	cout << "using tmie:" << (double)(end - start) / CLOCKS_PER_SEC * (1000) << "ms" << endl;
	//system("pause");
	return 0;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

WPF实战项目十七(客户端):数据等待加载弹框动画 1、在Common文件夹下新建文件夹Events,新建扩展类UpdateLoadingEvent。2、新建一个静态扩展类DialogExtensions来编写注册和推送等待消息弹框方法。3、在ViewModel中添加实现类NavigationViewModel。5、在View文件夹下新建用户控件ProgressView.xmal。4、在主窗体MainView.xmal中给弹窗界面命名。6、在MainView.xmal.cs中注册消息。 阅读详情

相关推荐

单细胞专题(1) | 单细胞转录组研究样本准备指南(上)

单细胞RNA测序(scRNA-seq)是目前最前沿,能进行大规模实验的转录组研究技术,为理解细胞组成和动态生物学过程提供了很多新的见解。单细胞研究已经为我们理解发育过程,老化和疾病(如癌症)等提供了大量数据。在这里,小编主要就前期的样本准备与保存需注意问题给大家进行讲解,以备大家在不同的研究场景和研究背景下,走好单细胞转录组学研究的第一步。

bioyigene的博客 4241

[POJ 2531]Network Saboteur[DFS]

题目链接:[POJ 2531]Network Saboteur[DFS] 题意分析: 将N个点的无向图分成两个部分,使得两部分之间连边的权值和最大。 解题思路: 2^N个状态,1e6大概,直接dfs枚举所有状态,设置一个数组in代表点属于哪个部分。不过计算权值和的时候明明是On啊,总最大复杂度,应该是2e7。 个人感受: 不知道为什么被归到了搜索优化剪枝专题里面= =,AC后强行好奇怎

闲停 638

绕过限制?实测修改UA在PC端运行微信小程序的可行性及风险

本文探讨了通过修改User-Agent(UA)在PC端运行微信小程序的技术可行性及风险。分析了小程序设备限制的技术原理,包括`wx.getSystemInfo`API和UA检测机制,并提供了多种修改方案及其局限性。同时强调了潜在的安全和法律风险,推荐使用官方模拟器或安卓模拟器等更安全的替代方案。

weixin_30879169的博客 388

POJ2531 Network Saboteur【DFS】

Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15990 Accepted: 7952 Description A university network is composed of N computers. System administrators gathered informati...

海岛Blog 672

DFT知识点扫盲——DFT scan chain

实际在项目中synccell一般直接上ULVT,既然是SDF,就是带Scan接口的DFF,SN (set negtive)是低置位,RP(reset positive)是高复位,既没有SN也没有RP的就是无复位寄存器。1:定义:满足可测试性设计(DFT),将设计中所有的触发器连接到一条或者若干条链上,称为scan chain,将一个复杂的时序电路转换为简单的组合电路进行测试,这一步是在逻辑综合(DC)中实现。当SE=1当SI=1时,电路进入scan状态,当SI=0时,电路工作在normal状态。

笨蛋大乌龟的博客 4953

Open Lovable 网站克隆AI工具超详细实战教程(含环境配置、排错与代码修改)

本教程面向有一定计算机基础的新手用户,提供一份全面、深入的 Open Lovable 使用指南。从开发环境搭建、API密钥获取、项目部署到网站克隆、代码下载、本地运行与二次开发,涵盖全流程细节与常见问题解决方案。通过本教程,新手可掌握如何利用AI驱动的Open Lovable工具,将任意目标网站智能复刻为结构清晰、可编辑的现代前端项目(React/Vite),实现快速原型开发与技术学习。

hy行者勇哥的博客 4996

POJ2531 Network Saboteur dfs

传送门:POJ2531 题意:有几台电脑,每两台电脑之间有固定的流量,要求将这些电脑分成两部分,使这两部分之间的流量总和最大。 解法:dfs搜索其中一堆,如果将第i台电脑加进去能将两部分之间的流量变大的话,就将这一台标记出来加入这一堆,并更新流量最大值,否则就放入另一堆。 #include #include #include using namespace std; int map[2

WA是一笔财富 278

Google Cameraserver 看门狗CameraServiceWatchdog超时crash原理分析

本文分析了Android CameraServiceWatchdog机制的工作原理。该看门狗用于监控相机服务关键操作(如close、flush)的超时情况,通过定时器线程检测阻塞问题。文章详细讲解了Watchdog的初始化流程、使能方式、内部定时器机制(默认周期100ms,650次循环触发超时),并提供了configureStreams阶段的客制化实现方案。当检测到超时,Watchdog会触发abort生成tombstone日志,便于调试分析。

1140

poj-2531 Network Saboteur(DFS)

Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17238 Accepted: 8677 Description A university network is composed of N computers. System administrators gathered information on the traffic between nodes, and carefully divided t

weixin_47750287的博客 247

最新Python爬虫实战(入门爬虫篇)——案例18:某气象局全国天气预报数据采集(详细爬虫思路截图 + 抓包动图演示+完整爬虫代码+详细注释)

本次案例针对某气象局天气预报网的静态HTML页面,实现了全国各地区天气数据的全自动化爬取,和之前案例17的动态接口爬虫不同,本次案例聚焦于静态页面的爬虫实现,覆盖了从抓包分析、请求模拟、数据解析到数据存储的完整爬虫流程,非常适合入门学习者巩固基础,核心知识点和实现要点总结如下:首先是页面分析的核心逻辑,静态HTML页面的数据爬取,核心在于通过浏览器开发者工具,完成完整的抓包分析和标签结构定位。

努力让自己发光,对的人才能迎着光而来 27万+

vmvare kali如何配置桥接模式进行上网

注意点:虚拟机可以PING通物理机,但是PING不通其他的网站。经过收集资料,得知由于是校园网连接,所以DHCP只能分配一个授权的IP地址给连接的主机,由于KALI是桥接物理机,物理机已经获得了这个授权的IP,所以导致桥接的虚拟机无法上网。所以不是因为配置的有问题,而是网络的安全设置导致了桥接失败。如果你是使用校园网,可以换个网络试试,使用校园网的时候,可能会遇到桥接失败。

猿小白的博客 1421

DFS Network Saboteur poj 2531

DFS Network Saboteur poj 2531

Dafang_Xu的博客 557

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

poj2531 Network Saboteur DFS枚举剪枝

http://poj.org/problem?id=2531 刚开始题意理解错了,看题解也没看懂。 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). 这句话很...

170

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

POJ2531 Network Saboteur DFS

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 stud

RUBGH的博客 208

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

【Poj 2531】 Network Saboteur dfs

Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10712 Accepted: 5152Description A university network is composed of N computers. System administrators gathere

ATOD 751

poj 2531 Network Saboteur——dfs

Network Saboteur 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 disg

five_east_west的博客 178

poj2531(dfs)Network Saboteur

poj2531看到这个题分类在dfs里,但是完全没有思路。。。看了下别人的博客。。先将所有点放在一个集合里,然后取出一个点放在另一个集合里,对于在同一个集合里的点,减去他们两个之间的权值,对于不在一个集合里的点,加上他们之间的权值。#include&lt;cstdio&gt; #include&lt;iostream&gt; #include&lt;cstring&gt; using namesp...

whiskey_wei的博客 359

DFS/POJ 2531 Network Saboteur

1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 int n,ans; 5 int a[30][30],f[30]; 6 int cmax(int a,int b){return a>b?a:b;} 7 void dfs(int x,int now) ...

diyoucang7967的博客 155

POJ 2531 Network Saboteur(DFS)

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 t...

邵光亮的博客 796

POJ 2531 Network Saboteur(dfs+剪枝)

题意就是把节点分成A、B两组,节点间距C给了,要求解分组的方法,使得∑Cij (i∈A,j∈B)最大。 #include #include #include #include #include using namespace std; const int inf = 0x3f3f3f3f; int edge[22][22],vis[22]; int flag,n; void dfs(

AK_HuangYC的博客 402

POJ 2531-Network Saboteur(DFS)

题目链接 题目大意: 将一个图的节点分为两部分,求两部分的通信距离最大. 解题思路: 竟然做了好几个小时,提交到POJ上超时,下面给出代码 首先我们将所有的点标记为0(即所有点放在一个集合里),然后取出一个site标记为1(即将该点放在另一个集合里),这是对于和site在一个集合里的点,我们减去他们两个之间的权值,对于不在一个集合里的点,我们加上他们之间的权值。最后的结果

小梁的编程学习之旅 373

poj 2531 Network Saboteur(dfs)

题意:有n个点,把这些点分别放到两个集合里,在两个集合的每个点之间都会有权值,求可能形成的最大权值。 n 看网上还有用NP、随机化什么什么的。。。都不会 等学了再回过来看看吧 代码: #include #include #include using namespace std; const int maxn = 25; int d[maxn][maxn], a[maxn],

CillyB的博客 490

POJ 2531 Network Saboteur(DFS)

Network Saboteur Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10216   Accepted: 4885 Description A university network is composed of N computers. System adm

Grit_ICPC的博客 746

POJ 2531 Network Saboteur (DFS)

Network Saboteur Time Limit:2000MS Memory Limit:65536K Total Submissions:9385 Accepted:4433 Description A university network is composed of N computers. System...

126

POJ - 2531 Network Saboteur 最大割 DFS

自己一开始没咋看明白,很多知识点都不知道。 转载两份代码。 第一份: 出处:http://exp-blog.com 大佬思想: 题目大意: 把一个完全图分成两部分,使得连接这两部分边的权和最大。 解题思路: 图论的无向完全图的最大割问题 (做网络最大流的时候同学们应该看过最小割,所以别问我什么是最大割了。。。不懂的百度去。。。) 可以用 随机化算法 Random Algorithm 去做 一开始我没读懂题,以为是求最大权。。。傻呼呼的用最了最小生成树的算法去做= = 一直RERERE。。。还以为是数组开得不

qq_45924838的博客 293
上一篇: HDU 1072 Nighmare 【BFS】
下一篇: POJ 1129 Channel Allocation【四色猜想+DFS染色】
Y390d
博客等级 码龄9年 11粉丝 165原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址