POJ 1160:Post Office 邮局经典DP

这篇博客详细介绍了如何解决POJ 1160题目的邮局选址问题,通过动态规划(DP)策略来避免暴力求解导致的时间超限。博主发现,当在a到b个村庄之间建立一个邮局时,最佳位置往往位于中间村庄。通过数学推导得出公式:sum[i][j]=sum[i][j-1]+value[j]-value[(i+j)/2],并利用该公式进行状态转移。最后,博主分享了如何初始化DP数组的起始值,即dp[1][i]=sum[1][i]。
摘要由CSDN通过智能技术生成

Post Office
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 17168   Accepted: 9270

Description

There is a straight highway with villages alongside the highway. The highway is represented as an integer axis, and the position of each village is identified with a single integer coordinate. There are no two villages in the same position. The distance between two positions is the absolute value of the difference of their integer coordinates. 

Post offices will be built in some, but not necessarily all of the villages. A village and the post office in it have the same position. For building the post offices, their positions should be chosen so that the total sum of all distances
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值