博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
noi.openjudge 2.6.162 Post Office
阅读量:5332 次
发布时间:2019-06-14

本文共 1535 字,大约阅读时间需要 5 分钟。

总时间限制: 
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 51 2 3 6 7 9 11 22 44 50
样例输出
9

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

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

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

转载于:https://www.cnblogs.com/ZGQblogs/p/9380865.html

你可能感兴趣的文章
eclipse工程重命名后,无法生产class问题
查看>>
第十章 call和ret指令
查看>>
关于字典序的若干问题
查看>>
ECMAScript6箭头函数ArrowFunction"=>"
查看>>
python 10大算法之二 LogisticRegression 笔记
查看>>
回到你身边
查看>>
Android项目打包成APK文件
查看>>
oracle exists
查看>>
vs2010 无法创建 *.edmx(Entity Frame Work) 文件的问题
查看>>
<C++>查询
查看>>
2019-07-29 CentOS安装
查看>>
Leetcode-944 Delete Columns to Make Sorted(删除列以使之有序)
查看>>
P1087-FBI树
查看>>
怎么在某个控制器中判断程序是否在前台或后台
查看>>
第三周vim入门学习1
查看>>
Linux内核分析(第九周)
查看>>
Serlvet学习笔记之一 ——实现servlet的3种方法
查看>>
批处理
查看>>
使用pycharm编写自动化脚本
查看>>
browser-sync启动命令
查看>>