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的更多相关文章

  1. noi.openjudge 1.13.44

    http://noi.openjudge.cn/ch0113/44/ 总时间限制:  1000ms 内存限制:  65536kB 描述 将 p 进制 n 转换为 q 进制.p 和 q 的取值范围为[2 ...

  2. noi.openjudge 1.13.15

    http://noi.openjudge.cn/ch0113/15/ 总时间限制:  1000ms 内存限制:  65536kB 描述 输入一个长度为N的整数序列 (不多于128个整数),每个整数的范 ...

  3. noi.openjudge 1.12.6

    http://noi.openjudge.cn/ch0112/06/ 总时间限制:  2000ms 内存限制:  65536kB 描述 传说很遥远的藏宝楼顶层藏着诱人的宝藏.小明历尽千辛万苦终于找到传 ...

  4. noi.openjudge——8465 马走日

    http://noi.openjudge.cn/ch0205/8465/ 查看 提交 统计 提问 总时间限制:  1000ms 内存限制:  1024kB 描述 马在中国象棋以日字形规则移动. 请编写 ...

  5. noi.openjudge——2971 抓住那头牛

    http://noi.openjudge.cn/ch0205/2971/ 总时间限制:  2000ms 内存限制:  65536kB 描述 农夫知道一头牛的位置,想要抓住它.农夫和牛都位于数轴上,农夫 ...

  6. noi openjudge 1768:最大子矩阵

    链接:http://noi.openjudge.cn/ch0406/1768/ 描述已知矩阵的大小定义为矩阵中所有元素的和.给定一个矩阵,你的任务是找到最大的非空(大小至少是1 * 1)子矩阵. 比如 ...

  7. noi openjudge 6044:鸣人和佐助

    http://noi.openjudge.cn/ch0205/6044/ 描述佐助被大蛇丸诱骗走了,鸣人在多少时间内能追上他呢? 已知一张地图(以二维矩阵的形式表示)以及佐助和鸣人的位置.地图上的每个 ...

  8. NOI题库7624 山区建小学(162:Post Office / IOI2000 POST OFFICE [input] )

    7624:山区建小学 Description 政府在某山区修建了一条道路,恰好穿越总共m个村庄的每个村庄一次,没有回路或交叉,任意两个村庄只能通过这条路来往.已知任意两个相邻的村庄之间的距离为di(为 ...

  9. noi 162 post office dp

    大致题意: 有v个村庄,每个村庄有各自的位置,且每个位置互不相同.现在要在村庄上设立P个邮局,使每个村庄到最近的邮局的距离之和最小. 分析: 定义状态d[i][j]表示前i个村庄,在这i个村庄中设立j ...

随机推荐

  1. PHP从入门到精通(六)

    PHP中的错误处理 1.PHP的错误级别:见表格.2.调整PHP错误报告级别:PHP中,调整错误报告级别的方式有两种: ①修改PHP.ini文件的配置项.a.会导致在当前服务器环境下所有PHP文件都受 ...

  2. linux及安全第八周总结

    进程的调度时机与进程的切换 操作系统原理中介绍了大量进程调度算法,这些算法从实现的角度看仅仅是从运行队列中选择一个新进程,选择的过程中运用了不同的策略而已. 对于理解操作系统的工作机制,反而是进程的调 ...

  3. 同步手绘板——json

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript的一个子集. JSON采用完全独立于语言的文本格式,但是也使用了类似于C语言家族 ...

  4. 注解Annotation

    @java.lang.annotation.Target(value={java.lang.annotation.ElementType.TYPE}) @java.lang.annotation.Re ...

  5. JSON数据格式解析

    JSON数据的语法规则 1.数据以键值对的形式 2.数据由逗号分隔 3.花括号保存对象 4.方括号保存数组 以PHP的数组为例: <?php $arr = array( "aaaa&q ...

  6. 全新OCR3500数据

    改装: 手变6700,夹器彦豪R741,牙盘5700,前拨5700,后拨5701,飞轮5700,链条YBN S10 S2,弯把DEDA RHM01,前叉山寨BIANCHI K-VID,轮组FULCRU ...

  7. phpstorm 注释模板

    /** * Created by ${PRODUCT_NAME}. * User: ${USER} * Date: ${DATE} * Time: ${TIME} */

  8. [转帖]Tensor是神马?为什么还会Flow?

    Tensor是神马?为什么还会Flow? 互联网爱好者 百家号17-05-2310:03 大数据文摘作品,转载要求见文末 编译 | 邵胖胖,江凡,笪洁琼,Aileen 也许你已经下载了TensorFl ...

  9. ubuntu安装命令

    sudo apt-get update  更新源sudo apt-get install package 安装包sudo apt-get remove package 删除包sudo apt-cach ...

  10. git如何拉取指定分支的代码

    问题背景: 新项目还在开发阶段,没有正式对外发布,所以开发同事合并代码到develop上(或者其他名称分支上),而不是到master分支上 通过git拉取代码的时候,默认拉取的是master分支,如下 ...