POJ 1160Post Office】的更多相关文章

POJ 1160    Post Office 我不知道优化,我只知道最暴力的方法,O(V^3),居然100ms不到的过了 设DP[i][j][k]表示考虑前i个小镇,放了j个邮局,最后一个邮局的所在城镇编号为k的k以前的所有的城镇距离最近的邮局的最小距离和(TM自己给自己搞了个这么绕的状态..) 那么有DP[i][j][i] = MIN{DP[i-1][j-1][k] + dis[k][i]}其中k<i DP[i][j][k] = DP[i-1][j][k] 其中,dis[k][i]表示[k,…
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 positio…
http://poj.org/problem?id=1160 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20218   Accepted: 10899 Description There is a straight highway with villages alongside the highway. The highway is represented as an integer axis, and the po…
http://poj.org/problem?id=1160 题意:直线上有n个城市,其中有p个城市有邮局,问如何建p个邮局使得每个城市到最近的邮局和最小.(n<=300, p<=30&p<=n) #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <iostream> using namespace st…
DP/四边形不等式 邮局,经典的四边形不等式例题! 关于四边形不等式的学习请看 赵爽论文<动态规划加速原理之四边形不等式> 题目总结&题解:http://blog.csdn.net/shiwei408/article/details/8791011 一个显而易见的结论是:对[l,r]这个区间内放一个邮局,放在中间的村子代价最小(类似中位数的感觉?...) 这道题我一开始想动规方程的时候想成[石子合并]那种了……实际上dp[i][j]表示的是前 j 个村庄一共建了 i 个邮局的最小花费……
Post Office Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15412   Accepted: 8351 Description There is a straight highway with villages alongside the highway. The highway is represented as an integer axis, and the position of each villa…
Post Office Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15966   Accepted: 8671 Description There is a straight highway with villages alongside the highway. The highway is represented as an integer axis, and the position of each villa…
Post Office Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22278 Accepted: 12034 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…
题目链接:http://poj.org/problem?id=1160 题目大意:在v个村庄中建立p个邮局,求所有村庄到它最近的邮局的距离和,村庄在一条直线上,邮局建在村庄上. 解题思路:设dp[i][j]表示到第i个村庄为止建立j个邮局的最小距离和,dis[i][j]表示i~j之间建一个邮局的最小距离和,我们很容易得出状态转移方程:dp[i][j]=min{dp[k][j]+dis[k+1][i]}(k<i). 主要是dis[i][j]的预处理很巧妙,从别人的博客上看的“将邮局建在i~j中间即…
题意: 给出m个村庄及其距离,给出n个邮局,要求怎么建n个邮局使代价最小. 析:一般的状态方程很容易写出,dp[i][j] = min{dp[i-1][k] + w[k+1][j]},表示前 j 个村庄用 k 个邮局距离最小,w可以先预处理出来O(n^2),但是这个方程很明显是O(n^3),但是因为是POJ,应该能暴过去..= =,正解应该是对DP进行优化,很容易看出来,w是满足四边形不等式的,也可以推出来 s 是单调的,可以进行优化. 代码如下: #pragma comment(linker,…