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 ...
随机推荐
- [2017BUAA软工]个人项目:数独
一.项目地址 https://github.com/Slontia/Sudoku 附加作业(GUI):https://github.com/Slontia/SudokuGUI 二.开发时间 PSP2. ...
- MySQL基础知识——范式与事务
几个概念 在说范式之前,要先了解几个概念: 关系模式 关系模式的5要素:R(U,D,DOM,F) 用下面这个category表来理解上面这个式子 mysql> desc student; +-- ...
- PHP文件系统操作常用函数
虽然PHP提供很多内置的文件处理函数,但是分得特别细,有一些操作需要多个函数一起使用才能达到目标,比如删除非空文件夹的所有内容,遍历文件夹等功能,下面各个函数是学习的时候整理的,有的是教程里的,有的是 ...
- 兼容IE-FireFox-Chrome的背景音乐播放
以music目录下的kn.mp3文件为例: <bgsound src="music/kn.mp3" loop="-1"/> <audio sr ...
- Laravel之路由 Route::get/post/any、路由参数、过滤器、命名、子域名、前缀、与模型绑定、抛出 404 错误、控制器
基本路由 应用中的大多数路都会定义在 app/routes.php 文件中.最简单的Laravel路由由URI和闭包回调函数组成. 基本 GET 路由 代码如下: Route::get('/', fu ...
- “一战通offer”互联网实习季编程挑战
1.字符串变形 对于一个给定的字符串,我们需要在线性(也就是O(n))的时间里对它做一些变形.首先这个字符串中包含着一些空格,就像"Hello World"一样,然后我们要做的是把 ...
- JavaScript中的Date对象在IOS中的“大坑”
在IOS5以上版本(不包含IOS5)中的Safari浏览器能正确解释出Javascript中的 new Date('2013-10-21') 的日期对象. 但是在IOS5版本里面的Safari解释ne ...
- mysql学习笔记二 —— 权限体系
要点: 1.MySQL的API2.MySQL的相关文件3.MySQL的权限体系 1.MySQL的API 应用程序接口 (application program interface) 1.1 命令行中的 ...
- 《ERP系统》客户信用及风控代码
1.风控核心代码: <?php namespace core\models; class SalesCustomersFacade extends \common\models\Base{ /* ...
- 关于super的理解,三篇文章支撑起来的
1.有向图的拓扑排序https://blog.csdn.net/wp1603710463/article/details/50900892 2. Python中MRO算法 http://mp.weix ...