[IOI 2000]POJ 1160 Post Office】的更多相关文章

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…
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…
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 题目大意:在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中间即…
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…
题意: 给出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,…
题意:有n个村庄,要在其中m个村庄里建邮局,每个村庄去邮局的代价为当前村庄到最近的一个有邮局村庄的路程,问总最小代价是多少. 解法:dp.dp[i][j]表示在前j个村庄建立i个邮局后的代价,则状态转移方程:dp[i][j] = min{dp[i - 1][k] + f(k + 1, j)},k = i - 1 ... j - 1,f(k + 1, j)表示在k + 1到j这些村庄中放一个邮局的代价,根据贪心的思想,这个邮局应该放在中间的村庄,即第(k + 1 + j) / 2个村庄,暴力的去算…
<题目链接> 转载于:>>> 题目大意: 一条高速公路,有N个村庄,每个村庄均有一个唯一的坐标,选择P个村庄建邮局,问怎么选择,才能使每个村庄到其最近邮局的距离和最小?最后打印这个最小值. 思路:典型的DP问题. 当我们在v个村庄中只建一个邮局,可以推导出,只有邮局位于中间位置,距离和才最小:有一个特殊情况是,当村庄数为偶数,中间位置有两个村庄,经过计算,两个村庄的距离和相等,所以俩位置均可. 可以联想到,N个村庄建P个邮局,相当于每个邮局均有一个作用范围,该邮局位于其作用范…
题目链接 \(Description\) 一条直线上有n个村庄,位置各不相同.选择p个村庄建邮局,求每个村庄到最近邮局的距离之和的最小值. \(Solution\) 先考虑在\([l,r]\)建一个邮局,最优解肯定是建在中间. 这样\(mid\)两边对称,距离和是最小的:若建在\(mid-1\),(假设\(mid\)与\(mid-1\)相距\(1\))虽然左边\(mid-1\)个村庄\(dis\)都\(-1\)了,但是右边有\(mid\)个村庄的\(dis\)会\(+1\). 如果区间长度为偶数…
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…