noi.openjudge 2.6.162 Post Office
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个邮局的距离和.
noi.openjudge 2.6.162 Post Office的更多相关文章
- noi.openjudge 1.13.44
http://noi.openjudge.cn/ch0113/44/ 总时间限制: 1000ms 内存限制: 65536kB 描述 将 p 进制 n 转换为 q 进制.p 和 q 的取值范围为[2 ...
- noi.openjudge 1.13.15
http://noi.openjudge.cn/ch0113/15/ 总时间限制: 1000ms 内存限制: 65536kB 描述 输入一个长度为N的整数序列 (不多于128个整数),每个整数的范 ...
- noi.openjudge 1.12.6
http://noi.openjudge.cn/ch0112/06/ 总时间限制: 2000ms 内存限制: 65536kB 描述 传说很遥远的藏宝楼顶层藏着诱人的宝藏.小明历尽千辛万苦终于找到传 ...
- noi.openjudge——8465 马走日
http://noi.openjudge.cn/ch0205/8465/ 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 1024kB 描述 马在中国象棋以日字形规则移动. 请编写 ...
- noi.openjudge——2971 抓住那头牛
http://noi.openjudge.cn/ch0205/2971/ 总时间限制: 2000ms 内存限制: 65536kB 描述 农夫知道一头牛的位置,想要抓住它.农夫和牛都位于数轴上,农夫 ...
- noi openjudge 1768:最大子矩阵
链接:http://noi.openjudge.cn/ch0406/1768/ 描述已知矩阵的大小定义为矩阵中所有元素的和.给定一个矩阵,你的任务是找到最大的非空(大小至少是1 * 1)子矩阵. 比如 ...
- noi openjudge 6044:鸣人和佐助
http://noi.openjudge.cn/ch0205/6044/ 描述佐助被大蛇丸诱骗走了,鸣人在多少时间内能追上他呢? 已知一张地图(以二维矩阵的形式表示)以及佐助和鸣人的位置.地图上的每个 ...
- NOI题库7624 山区建小学(162:Post Office / IOI2000 POST OFFICE [input] )
7624:山区建小学 Description 政府在某山区修建了一条道路,恰好穿越总共m个村庄的每个村庄一次,没有回路或交叉,任意两个村庄只能通过这条路来往.已知任意两个相邻的村庄之间的距离为di(为 ...
- noi 162 post office dp
大致题意: 有v个村庄,每个村庄有各自的位置,且每个位置互不相同.现在要在村庄上设立P个邮局,使每个村庄到最近的邮局的距离之和最小. 分析: 定义状态d[i][j]表示前i个村庄,在这i个村庄中设立j ...
随机推荐
- cross-env简介
是什么 运行跨平台设置和使用环境变量的脚本 出现原因 当您使用NODE_ENV =production, 来设置环境变量时,大多数Windows命令提示将会阻塞(报错). (异常是Windows上的B ...
- 第三周作业————————word count
#include <stdio.h> void main() { FILE *fp; , str, word, pu, ch; int g; str = ; word = ; pu = ; ...
- 对于windows 10使用感受
windows 10是美国微软公司研发的新一代跨平台及设备应用的操作系统.在2015年7月29日12点起,windows 10推送全面开始,windows 7.windows 8 用户可以升级到win ...
- [2019BUAA软件工程]第1次阅读作业
[2019BUAA软件工程]第1次阅读作业 Tips Link 作业连接 [2019BUAA软件工程]第1次阅读作业 读<构建之法>的疑惑 个人开发流程(Personal Software ...
- 使用代理创建连接池 proxyPool
配置文件properties url=jdbc:mysql://127.0.0.1:3306/mine?characterEncoding=UTF-8 user=root password=1234 ...
- Beta之后的想法
软件工程如果没选实践,单纯在理论课上面对教条化的理论,这些理论都是很有指导意义的,但没有实践课带来的切实的多人团队合作开发项目的实际体会,很难能领会到其中的深意.知行合一,才能发现软件工程里的知识都是 ...
- python中的hasattr()、getattr()、setattr()
hasattr()的用法和理解--hasattr(obj, target) 判断对象obj中是否含有,目标target属性,然后返回布尔值,如果有返回True,没有返回False. >>& ...
- ubuntu在windows下的wubi安装
转自:http://mp.weixin.qq.com/s?__biz=MjM5NjYxNjU0OQ==&mid=200664819&idx=2&sn=25719890570b1 ...
- Docker Dockerfile指令
Docker 可以通过 Dockerfile 的内容来自动构建镜像.Dockerfile 是一个包含创建镜像所有命令的文本文件,通过docker build命令可以根据 Dockerfile 的内容构 ...
- js拷贝实例;
,]]; // var arr2 =arr1.slice(0); // arr1[0] ="z"; // arr1[2][0] = "v"; // consol ...