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 ...
随机推荐
- 状态模式-State-订单状态
JAVA设计模式-状态模式-State-订单状态 21. State(状态) 意图: 允许一个对象在其内部状态改变时改变它的行为.对象看起来似乎修改了它的类. 解释: 比如说对订单的提交,第一 ...
- 《Linux内核设计与实现》第五章学习笔记
<Linux内核设计与实现>第五章学习笔记 姓名:王玮怡 学号:20135116 一.与内核通信 在Linux中,系统调用是用户空间访问内核的唯一手段:除异常和陷入外,它们是内核 ...
- 第三个Sprint ------第四天
出题代码 package com.app.senior_calculator; import java.io.Serializable; public class Question implement ...
- A example that using JQuery clone
<html> <head> <script type="text/javascript" src="/jquery/jquery.js&qu ...
- linux_目录基本操作
ls命令 ls命令用来显示目标列表,在Linux中是使用率较高的命令.ls命令的输出信息可以进行彩色加亮显示,以分区不同类型的文件. 语法 $ ls [选项] [目录] 选项 说明 -a 显示所有档案 ...
- php的一些算法题
1.有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,请编程输出两年内每个月的兔子总数为多少? <?php function getRes ...
- 归并排序详解(python实现)
因为上个星期leetcode的一道题(Median of Two Sorted Arrays)所以想仔细了解一下归并排序的实现. 还是先阐述一下排序思路: 首先归并排序使用了二分法,归根到底的思想还是 ...
- Spring学习14-源码下载地址
今天想下载一下Spring的源代码,登录到Spring官网,傻眼了,根本找不到下载的地方!费了九牛二虎之力在网上找到了一个下载地址,记下来,免得下次再次傻找. http://s3.amazonaws. ...
- rgb & rgba convert
rgb & rgba convert RGB color to Hex, Pantone, RAL, HSL, HSV, HSB, JSON. Get color scheme. https: ...
- XHTML 簡介
XTML是可擴展的超文本標記語言. XHTML是比HTML更加嚴謹的HTML語言. 所有的瀏覽器都能識別XHTML. XHTML符合W3C標準,是為了替代HTML的.