描述:

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

运用dp背包的方法,对于不理解的就把代码背下来。

#include<iostream>
#include<string.h>
using namespace std;
int bns[1010][1010],w[1010][1010],ans[1010];
int main()
{int n,k;cin>>n>>k;for(int i=1;i<=n;i++)cin>>ans[i];memset(w,0,sizeof(w));for(int i=1;i<=n;i++){for(int j=i+1;j<=n;j++){w[i][j]=w[i][j-1]+ans[j]-ans[(i+j)/2];}}memset(bns,0x3f3f3f3f,sizeof(bns));for(int i=1;i<=n;i++){bns[i][1]=w[1][i];bns[i][i]=0;}for(int i=2;i<=k;i++){for(int j=i+1;j<=n;j++){for(int l=i-1;l<=j-1;l++){bns[j][i]=min(bns[j][i],bns[l][i-1]+w[l+1][j]);}}}cout<<bns[n][k]<<endl;return 0;
}

Post Office相关推荐

  1. 计算机二级函数知识,2017年全国计算机二级考试MS Office高级应用知识点:INDIRECT函数...

    INDIRECT函数知识点 适用考试:全国计算机二级考试 考试科目:MS Office高级应用 科目知识点:INDIRECT函数 INDIRECT函数立即对引用进行计算,并显示其内容.当需要更改公式中 ...

  2. 计算机二级ms office excel,计算机二级Msoffice考试excel答案.docx

    操作题1: 1.解题步骤: 步骤1:启动考生文件下的"Excel. xlsx",打开"订单明细表"工作表. 步骤2:选中工作表中的A2:H636,单击[开始]选 ...

  3. 仿百度文库方案[openoffice.org 3+swftools+flexpaper](三) 之 使用JODConverter将office文档转换为pdf...

    第三步,使用JODConverter将office文档转换为pdf JODConverter是一个java的OpenDucument文件转换器,可以进行许多文件格式的转换,它利用 OpenOffice ...

  4. 和Office一起做减肥操

    随着微软公司的不断开发,Microsoft Office这款大家熟悉的软件真是越来越好用.可是随着版本的更新,软件的身材却越来越"肥胖",于是很多朋友总想知道如何给它们" ...

  5. 计算机rsnge指令,计算机二级office Excel 函数复习重点

    原标题:计算机二级office Excel 函数复习重点 计算机二级来袭! 近期,计算机二级考试即将开始,小编在这里为大家奉上众多难点中的一个考点的详解--<excel函数的应用>,希望能 ...

  6. XDOC Office Server 开源了,Office文档完美转换为PDF

    百度智能云 云生态狂欢季 热门云产品1折起>>>   项目地址:https://gitee.com/xdoc/xoffice XDOC是一个文档自动化平台,提供免费的Office文档 ...

  7. VDI序曲二十三 制作OFFICE 2003应用程序虚拟化序列

    APP-V平台由三个重要组件构成:APP-V排序器.用于虚拟应用程序交付和管理的APP-V管理和流式处理服务器以及APP-V客户端.并且在虚拟环境中不会包含不必要的文件和设置,让IT管理员按需交付应用 ...

  8. Lync server 2013 之office web apps server 搭建步骤

    office web apps server 搭建步骤: 一. .NET Framework 4.5 节点下的HTTP 激活 .NET Framework 3.5 Windows Identity F ...

  9. Office 2016使用NTKO OFFICE控件提示“文件存取错误”的解决办法

    2019独角兽企业重金招聘Python工程师标准>>> 之前使用NTKO,电脑安装的说OFFICE2007,但是前2天电脑固态硬盘坏了 ,重新安装了系统,安装的说win10和offi ...

  10. Office 365 系列之一:初识Office 365

    最近项目越来越多,压力也是越来越大,而且到了年底了还要进行Office 365的考试,最近小编是在闲暇之余各种查看Office 365的资料,今天跟大家分享自己对 Office 365 的学习和理解, ...

最新文章

  1. ACL 2016 | CopyNet 和 Pointer Softmax
  2. 如何在linux(ubuntu)的wine环境下开启source insight的tabsihost(或tabsiplus)
  3. android 5.0 新功能,Android 5.0新特性有哪些?安卓5.0新功能汇总
  4. 什么是URL转发和一个IP建多个Web站点--主机头名法
  5. Oracle典型应用场景--数据迁移到本地测试
  6. 如何解决/home/oracle: is a directory报警
  7. Rsync安装与配置
  8. php获取pc访问还是手机号_PHP函数判断电脑端浏览器访问访问还是手机端浏览器访问...
  9. 【POJ】2454.Jersey Politics
  10. 广东省计算机应用专业综合理论知识,(计算机应用技术专业综合理论考试说明.doc...
  11. android unit(px,dp,dip,sp)
  12. linux windows下重启oracle
  13. DOD,与cisco三层模型
  14. json多层集合转对象
  15. pg8168改mac命令_使用PG8168修改8111b网卡MAC地址
  16. DBF文件使用JAVA读写解决方案
  17. oracle的安装教程
  18. 锁定计算机耗电吗,我想知道电脑在待机情况下费电吗?
  19. 期权和期货的定义及区别
  20. java计算机毕业设计合同管理MyBatis+系统+LW文档+源码+调试部署

热门文章

  1. 《 ERP高级计划》书的解读-APS算法分析之七分解技术(DT)(蔡颖)(转)
  2. 《苏菲的世界》读书笔记之一:自然派哲学家
  3. 亚马逊广告api v2版php扩展库
  4. 接口报错500是什么意思_500错误原因解决办法?错误页面怎么解决?到底是什么问题?...
  5. 《斩魔问道》突破传统玩法,实时强战PK,爆裂高清画质的仙侠手游巨作
  6. 计蒜客——恋爱纪念日(学习如何格式化打印日期)
  7. java中OOP的概念之我见
  8. 知其然也知其所以然,Redis笔记总结:核心原理与应用实践
  9. 利用C语言实现大数加减法
  10. linux pv命令,linux运维系列pv指令