noi.openjudge 2.6.162 Post Office

0人阅读 评论(0) 收藏 举报
分类:

http://noi.openjudge.cn/ch0206/162/

总时间限制: 
1000ms
内存限制: 
65536kB
描述
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 between each village and its nearest post office is minimum.

You are to write a program which, given the positions of the villages and the number of post offices, computes the least possible sum of all distances between each village and its nearest post office. 
输入
Your program is to read from standard input. The first line contains two integers: the first is the number of villages V, 1 <= V <= 300, and the second is the number of post offices P, 1 <= P <= 30, P <= V. The second line contains V integers in increasing order. These V integers are the positions of the villages. For each position X it holds that 1 <= X <= 10000.
输出
The first line contains one integer S, which is the sum of all distances between each village and its nearest post office.
样例输入
10 5
1 2 3 6 7 9 11 22 44 50
样例输出
9



这一题你们去看别人的博客吧,我不想写了.

简单来说sum表示的是,从i到k,建一个邮局的距离和

dp表示前i个房子,建j个邮局的距离和.


查看评论

poj——1160——Post Office

题目:用数轴描述一条高速公路,有V个村庄,每一个村庄坐落在数轴的某个点上,需要选择P个村庄在其中建立邮局,要求每个村庄到最近邮局的距离和最小。 分析:经典DP 1、考虑在V个村庄中只建立一个邮局的...
  • u011470356
  • u011470356
  • 2014-01-20 14:40:00
  • 646

poj - 1160 - Post Office(dp)

题意:一条直路上有V个村庄(1 题目链接:http://poj.org/problem?id=1160 ——>> 状态:dp[i][j]表示前i个村庄建j个邮局的最短距离和。 状态转移方程:dp[i...
  • SCNU_Jiechao
  • SCNU_Jiechao
  • 2014-10-21 16:34:55
  • 1454

【POJ 1160】Post Office

四边形优化dp转移经典题目~
  • Regina8023
  • Regina8023
  • 2015-03-13 15:27:13
  • 906

POJ 1160:Post Office 邮局经典DP

Post Office Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17168   A...
  • u010885899
  • u010885899
  • 2015-08-04 22:28:15
  • 1116

poj 1160 Post Office(动态规划:较难)

求把p个邮局建在v个村庄对应的最小距离
  • u011639256
  • u011639256
  • 2014-08-29 15:48:42
  • 536

poj 1160 Post Office //四边形不等式优化

四边形不等式优化------邮局问题m[p,n]为问题的解m[i,j]表示在前j个村庄建立i个邮局的最小距离和状态转移方程和边界条件是m[1,j]=w[1,j]m[i,j]=min(m[i-1,k]+...
  • hqd_acm
  • hqd_acm
  • 2011-03-02 12:19:00
  • 2585

Control Panel - Post Office Admin

  • 2006年02月23日 09:05
  • 1KB
  • 下载

ACM-ICPC Live Archive 第4889题 Post Office

ACM-ICPC Live Archive 第4889题,Post Office(题目链接)。 Post Office Problem Description Other than post...
  • yjf_victor
  • yjf_victor
  • 2015-04-15 22:12:04
  • 4240

pku1160 Post Office

题目链接:http://acm.pku.edu.cn/JudgeOnline/problem?id=1160题意简述:有n个村庄,m个邮局,给定各村庄的坐标位置,求n个村庄建立m个邮局使得所有村庄距它...
  • ccsu_001
  • ccsu_001
  • 2009-10-15 20:34:00
  • 871

UVALive 7960|Gym 101201I|Postman|贪心

DescriptionA postman delivers letters to his neighbors in a one-dimensional world. The post office,...
  • huanghongxun
  • huanghongxun
  • 2017-12-09 21:06:30
  • 111
    个人资料
    持之以恒
    等级:
    访问量: 206
    积分: 154
    排名: 110万+
    文章分类
    文章存档
    最新评论