HDU3879 Base Station 最大权闭合图/最大密度子图 2011 Multi-University Training Contest 5 - Host by BNU

HDU2059龟兔赛跑-题解动态规划DP 龟兔赛跑<br />Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)<br />Total Submission(s): 3538    Accepted Submission(s): 1277<br /><br />Problem Description据说在很久很久以前,可怜的兔子经历了人生中最大的打击——赛跑输给乌龟后,心中郁闷,发誓要报仇雪恨,于是躲进了杭州下沙某农业园卧薪尝胆潜心修 阅读详情
 

Base Station

Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65768/32768 K (Java/Others)
Total Submission(s): 394 Accepted Submission(s): 143


Problem Description
A famous mobile communication company is planning to build a new set of base stations. According to the previous investigation, n places are chosen as the possible new locations to build those new stations. However, the condition of each position varies much, so the costs to built a station at different places are different. The cost to build a new station at the ith place is P i (1<=i<=n).

When complete building, two places which both have stations can communicate with each other.

Besides, according to the marketing department, the company has received m requirements. The ith requirement is represented by three integers A i, B i and C i, which means if place A i and B i can communicate with each other, the company will get C i profit.

Now, the company wants to maximize the profits, so maybe just part of the possible locations will be chosen to build new stations. The boss wants to know the maximum profits.

Input
Multiple test cases (no more than 20), for each test case:
The first line has two integers n (0<n<=5000) and m (0<m<=50000).
The second line has n integers, P1 through Pn, describes the cost of each location.
Next m line, each line contains three integers, A i, B i and C i, describes the ith requirement.

Output
One integer each case, the maximum profit of the company.

Sample Input
  
5 5 1 2 3 4 5 1 2 3 2 3 4 1 3 3 1 4 2 4 5 3

Sample Output
  
4

Author
liulibo

Source

Recommend
lcy
 
同NOI2006 最大获利一样,题解详见国家集训队2007论文 胡伯涛  《最小割模型在信息学竞赛中的应用》
 
第一眼看到就觉得是网络流,再看数据范围傻眼了,n=5000,m=50000
这题用网络流N=55000,M=400000
而ISAP和Dinic复杂度是O(N^2M),网络流最快也才O(N^3),我以为特定超时,于是怀疑不是网络流。
最后WSN告诉我就是网络流,我拿Dinic模板提交果然TLE了。。。
WSN给了我一个Dinic模板,竟然AC了,不过没看懂优化部分!
原来O(N^2M)只是Dinic的复杂度上限,一般都达不到这个极限。
看来以后分析复杂度的时候也不能完全依赖理论复杂度啊。
论文说还可以转换为最大密度子图,不过实现麻烦,不知道效率怎么样。
 
代码:
 
 
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 55005
#define M 320005
#define inf 999999999
using namespace std;

int n,m,s,t,num,adj[N],dis[N],q[N];
struct edge
{
	int v,w,pre;
}e[M];
void insert(int u,int v,int w)
{
	e[num]=(edge){v,w,adj[u]};
	adj[u]=num++;
	e[num]=(edge){u,0,adj[v]};
	adj[v]=num++;
}
int bfs()
{
	int i,x,v,tail=0,head=0;
	memset(dis,0,sizeof(dis));
	dis[s]=1;
	q[tail++]=s;
	while(head<tail)
	{
		x=q[head++];		
		for(i=adj[x];i!=-1;i=e[i].pre)
			if(e[i].w&&dis[v=e[i].v]==0)
			{
				dis[v]=dis[x]+1;
				if(v==t)
					return 1;
				q[tail++]=v;
			}
	}
	return 0;
}
int dfs(int s,int limit)
{
	if(s==t)
		return limit;
	int i,v,tmp,cost=0;
	for(i=adj[s];i!=-1;i=e[i].pre)
		if(e[i].w&&dis[s]==dis[v=e[i].v]-1)
		{
			tmp=dfs(v,min(limit-cost,e[i].w));
			if(tmp>0)
			{
				e[i].w-=tmp;
				e[i^1].w+=tmp;
				cost+=tmp;
				if(limit==cost)
					break;
			}
			else dis[v]=-1;
		}
	return cost;
}
int Dinic()
{
	int ans=0;
	while(bfs())
		ans+=dfs(s,INT_MAX);
	return ans;
}
int main ()
{
	while(~scanf("%d%d",&n,&m))
	{
		int i,u,v,w,sum=0;
		memset(adj,-1,sizeof(adj));
		num=0;
		s=0;
		t=n+m+1;
		for(i=1;i<=n;i++)
		{
			scanf("%d",&w);
			insert(i+m,t,w);
		}
		for(i=1;i<=m;i++)
		{
			scanf("%d%d%d",&u,&v,&w);
			insert(s,i,w);
			insert(i,u+m,inf);
			insert(i,v+m,inf);
			sum+=w;
		}
		printf("%d\n",sum-Dinic());
	}
}

 
最大密度子图:
详细分析过程见胡伯涛的论文《最小割模型在信息学竞赛中的应用》
设U=2*sum(Wv)+sum(We)
s到i连边,边权为U
原图u->v,则u到v,v到u连边,边权为We
i到t连边,边权为U+2*Wv-sum(Wvi)
答案是U*n-MaxFlow
代码:
#include<cstdio>   
#include<cstring>   
#include<algorithm>   
#define N 5005   
#define M 300005   
#define inf 999999999   
using namespace std;  
  
int n,m,s,t,num,adj[N],dis[N],q[N],d[N];  
struct edge  
{  
    int v,w,pre;
	edge(){}
	edge(int vv,int ww,int p){v=vv;w=ww;pre=p;}
}e[M];  
void insert(int u,int v,int w)  
{  
    e[num]=edge(v,w,adj[u]);  
    adj[u]=num++;  
    e[num]=edge(u,0,adj[v]);  
    adj[v]=num++;  
}  
int bfs()  
{  
    int i,x,v,tail=0,head=0;  
    memset(dis,0,sizeof(dis));  
    dis[s]=1;  
    q[tail++]=s;  
    while(head<tail)  
    {  
        x=q[head++];          
        for(i=adj[x];i!=-1;i=e[i].pre)  
            if(e[i].w&&dis[v=e[i].v]==0)  
            {  
                dis[v]=dis[x]+1;  
                if(v==t)  
                    return 1;  
                q[tail++]=v;  
            }  
    }  
    return 0;  
}  
int dfs(int s,int limit)  
{  
    if(s==t)  
        return limit;  
    int i,v,tmp,cost=0;  
    for(i=adj[s];i!=-1;i=e[i].pre)  
        if(e[i].w&&dis[s]==dis[v=e[i].v]-1)  
        {  
            tmp=dfs(v,min(limit-cost,e[i].w));  
            if(tmp>0)  
            {  
                e[i].w-=tmp;  
                e[i^1].w+=tmp;  
                cost+=tmp;  
                if(limit==cost)  
                    break;  
            }  
            else dis[v]=-1;  
        }  
    return cost;  
}  
int Dinic()  
{  
    int ans=0;  
    while(bfs())  
        ans+=dfs(s,INT_MAX);  
    return ans;  
}  
int main ()  
{  
    while(~scanf("%d%d",&n,&m))  
    {  
        int i,u,v,w[N],U=1000000;  
		memset(d,0,sizeof(d));
        memset(adj,-1,sizeof(adj));  
        num=0;
        s=0;
        t=n+1;
        for(i=1;i<=n;i++) 
		{			
			scanf("%d",w+i);
			insert(s,i,U);
		}
        for(i=1;i<=m;i++)  
        {  
            scanf("%d%d%d",&u,&v,w);
			d[u]+=w[0];
			d[v]+=w[0];
            insert(u,v,w[0]);  
            insert(v,u,w[0]);  
        }
		for(i=1;i<=n;i++)
			insert(i,t,U+2*w[i]-d[i]);
        printf("%d\n",(U*n-Dinic())/2);  
    }  
}  

 
环形m段最大子段和 题解动态规划DP http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=10581环形m段最大子段和Time Limit: 5000ms, Special Time Limit:15000ms, Memory Limit:65536KB Total submit users: 3, Accepted users: 3 Problem 10581 : No special judgementProblem description  我想你已经做出了一维的最大子段 阅读详情

相关推荐

单神经元PID控制:从Hebb到Delta,四种学习规则在MATLAB里到底怎么选?

本文深入探讨了单神经元PID控制算法在MATLAB中的四种学习规则(无监督Hebb、有监督Delta、有监督Hebb及改进Hebb)的实战对比与选型指南。通过详细的仿真实验和性能指标分析,为工程师提供了基于实际工程考量的选型建议和参数整定技巧,帮助优化复杂非线性系统的控制效果。

weixin_31220401的博客 283

HDU 3879 Base Station 最大权闭包 2011 Multi-University Training Contest 5 - Host by BNU

/* 建立点到汇点的边,边权的点值 抽象边为点(边点),建立源点到边点的边,边权为原的边权 建立边点到其原先连的点的两条边,边权无穷, 求最大流。答案为所有原边权和减去最大流 */ #include #include #include #include #include

Join Hands 1249

睿尔曼超轻量仿人机械臂--医疗工作站运行Demo(Python)

开发环境系统:win10Python版本:python 3.11.2由于机械臂相关软件版本不定期更新,如果你使用的软件接口或协议与本文有出入,请联系官方技术人员及时更新。

realman_Rop的博客 1094

POJ 3155 Hard Life 最大密度子图

Hard Life Time Limit: 8000MS   Memory Limit: 65536K Total Submissions: 4345   Accepted: 1226 Case Time Limit: 2000MS

魔神翼 3909

c语言【分糖果】2023蓝桥杯4124(枚举,递归,dfs)

但是这是不符合我们糖果刚好分完的条件的,我们应该往回退到上一层,也就是孩子6这层,然后j+1=3,孩子7分到3个第二种糖果,这也不符合我们糖果刚好分完的条件,然后就会再次回退到孩子6这里,然后j+1=4,让我们的孩子7获得5块第二种糖果,然后还是不符合糖果刚分完的条件,于是再一次退回到孩子6这里,然后就会有外循环i+1=1,j=1,孩子7分到1块第一种糖果1块第二块糖果......然后就是这样的不停地回溯,试探,直到把整棵树遍历一遍,并且记录所有的满足条件的组合。先放一下我的代码,我的代码超时啦救命!

weixin_74331419的博客 732

NRF52832调试方法1——HardFault_Handler问题定位

一、遇到问题 keil debug模式下,直接点击全速运行(Run)发现程序卡死,点击stop按钮后,停到了HardFault_Handler位置,如下图所示。 此时使用navigate backwards(蓝色左箭头)是无效的,找不到程序卡在哪里。 二、解决办法 此时首先观察register窗口 若Stack为MSP,则复制R13(SP)的值到memory观察窗的地址搜索栏。每一行显示连续的28个地址上的存储信息,每个地址上存有一个字节。 从第21个位置起的连续四个字节是LR的值,

小梁的博客 3651

HDU 4069 Squiggly Sudoku 数独DLX 福州网络赛

Squiggly Sudoku Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 644 Accepted Submiss

魔神翼 3899

从 ABAP 后端到 AEX,Local Integration Engine 下的 Business System 配置全景

本文围绕SAP PI AEX配置中ABAP后端系统与AEX的连接问题,梳理了关键概念和技术脉络。重点指出基于ABAP 6.20及更高版本的业务系统内置了本地集成引擎(Local Integration Engine),负责与AEX的消息交互。配置要点包括:1)在SM59中创建HTTP类型RFC目标连接AEX;2)配置SAP_PROXY_ESR供设计时代理生成;3)通过SXMB_ADM设置业务系统角色为应用系统;4)确保SLD注册和SICF服务激活。文章特别强调运行时代理消息传递与设计时代理生成的区分,以及H

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 99

HDU 3696 FZU 2006 -- Farm Game SPFA最长路 2010福州区域赛

Farm Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 62768/32768 K (Java/Others) Total Submission(s): 148 Accepted Submission(s): 65 Problem Description “Farm Game” is one of the m

魔神翼 3708

ISO2626 --- Item Definition相关项定义

本文并不是针对ISO26262的一个项目,而是针对ISO26262的规范,我们在相关项定义阶段,我们需要做什么,我们的文档需要包含哪些内容的一个描述。

wj博客 909

MySQL——cost成本计算之MySQL如何选择使用索引(trace)

文章目录前言trace工具分析执行计划 前言 在之前博客中,根据测试案例,发现同样的sql语句,因为传入的条件值的不同,导致MySQL有时候选择使用索引,有时候又不适用索引。 如下所示sql的执行计划: EXPLAIN SELECT * FROM employees WHERE name > 'aaa'; EXPLAIN SELECT * FROM employees WHERE name > 'zzzz'; 在MySQL中,为什么会出现上述这种玄乎的现象呢? 本篇博客重点说明原因。 在说

专注写bug 679

SOJ2113: 数字游戏题解动态规划DP

2113: 数字游戏Submit your solution     Discuss this problem     Best solutionsDescription 【问题描述】 丁丁最近沉迷于一个数字游戏之中。这个游戏看似简单,但丁丁在研究了许多天之后却发觉原来在简单的规则下想要赢得这个游戏并不那么容易。游戏是这样的,在你面前有一圈整数(一共n个),你要按顺序将其分为m个部分,各部分内的数字相加,相加所得的m个结果对10取模后再相乘,最终得到一个数k。游戏的要求是使你所得的k最大或者最小。 例如,对

魔神翼 3589

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

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

[SCOI2009]windy数 题解动态规划DP

[SCOI2009]windy数 Time Limit:1000MS  Memory Limit:165536KTotal Submit:162 Accepted:74 Descriptionwindy定义了一种windy数。 不含前导零且相邻两个数字之差至少为2的正整数被称为windy数。 windy想知道,在A和B之间,包括A和B,总共有多少个windy数? Input包含两个整数,A B。 Output一个整数。 Sample Input【输入样例一】 1 10 【输入样例二】 25 50

魔神翼 3430

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

POJ3662 Telephone Lines 二分+最短路

Telephone Lines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3468   Accepted: 1245 Description Farmer John wants to set up a telephone line at his farm.

魔神翼 3200

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

POJ3186Treats for the Cows题解动态规划DP

Treats for the CowsTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 2686 Accepted: 1280<br />DescriptionFJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving vast amounts of milk. FJ sells one treat per day and wan

魔神翼 3032

POJ1651Multiplication Puzzle题解动态规划DP

Multiplication PuzzleTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 3460 Accepted: 2034<br />DescriptionThe multiplication puzzle is played with a row of cards, each containing a single positive integer. During the move player takes one card out

魔神翼 2831

HDU2821 Pusher HDU3500 Fling DFS搜索

Pusher Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others) Total Submission(s): 169 Accepted Submission(s): 6

魔神翼 2686

HDU4067 Random Maze 最小费用最大流 福州网络赛

Random Maze Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 243 Accepted Submission

魔神翼 2669

POJ1018Communication System题解动态规划DP

Communication SystemTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 12607 Accepted: 4377<br />DescriptionWe have received an order from Pizoor Communications Inc. for a special communication system. The system consists of several devices. For eac

魔神翼 2217

HDU 3605 Escape 最大流or二分图多重匹配 2010 ACM-ICPC Multi-University Training Contest(17)——Host by ZSTU

Escape Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1122 Accepted Submission(s):

魔神翼 2058

HDU 3681 Prison Break 二分+搜索 The 35th ACM-ICPC Asia Regional Contest (Hangzhou)

Prison Break Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1076 Accepted Submissio

魔神翼 2028

五十三.网络(3)--区块同步getblocks消息

在节点互发了version消息后,就会发送getblocks消息,请求对方的区块以进行同步。

d3582077的专栏 177

Linux 服务器性能排查手册(2026):CPU、内存、磁盘IO、网络四大瓶颈定位

iptables 四表五链模型、firewalld zone 信任级别、云安全组与主机防火墙的关系与优先级,避坑改了防火墙把自己挡在服务器外面的翻车事故。

2502_91473995的博客 338

AI 芯片片上网络 NoC 深度解析:flit、虚通道与拥塞控制如何决定 GPU/TPU/LPU 的算力利用率

AI芯片算力瓶颈不在FLOPS,而在片上网络(NoC)——数据搬运的能耗与延迟决定MFU上限。物理限制下,长线延迟不随工艺缩小,迫使NoC将全局布线拆为可流水的短链路;能量账显示,一跳传输耗能可达数十次乘加操作。拓扑选择直接影响性能:二维mesh虽布线可行,但均匀流量下每节点可用带宽按1/√N衰减,实测仅达标称值30%。虚通道、双网设计、静态调度(如Groq)等技术旨在突破此瓶颈。从总线到crossbar再到多跳NoC,本质是用延迟换可行性。未来趋势:专用通路(脉动阵列)、晶圆级集成(Cerebras)、跨

我的博客 108

网安产教融合思考:如何补齐高校实战能力评价短板

不少网安专业高校都面临这样现实的难题:网安人才培养持续推进,校内已经搭建完整的教学体系,但高校培养方案可能几年修一次,企业的技术栈和攻击手法却按季度在变,学校难落地最新的技术实战教学,学生难证明实战本领,企业一边喊人才紧缺,一边感慨招不到来了就能干的应届生。网安时代,实战为王。备考平台、7天免费直播培训、免费认证考试,期待更多高校加入 CCP 人才共育生态,组织本校学子参与本轮认证,以认证带动教学,以实战对接就业,共同为行业培养 “用得上、干得好” 的实战型网络安全人才。本次报名、培训、考试全程免费,

A19911511842的博客 190
上一篇: 网络流题目集锦
下一篇: Sudoku 数独 Dancing Links模板
power721
博客等级 码龄19年 176粉丝 135原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值