编程介的小学生 2019-12-20 17:53 采纳率: 20.5%
浏览 76

Little Sheep 问题如何实现的

Problem Description
As we all know, sheep are very lazy, they don’t like move and just want to enjoy delicious food. So, Mr. LittleSheep who is in charge of a farm which owns lots of sheep is extremely tired in feeding these sheep. Mr. LittleSheep’s farm is like a circle consists of n corrals, each corral has a certain number of sheep, and every corral has a door for feeding. When it comes to feeding time, Mr. LittleSheep has to decide in which orders should he open those doors, because he can just open one door every time, otherwise these tricky sheep would run away. When the door is opened, the lazy sheep whose distance to the open door less or equal to k will go out, the distance to the open door is defined by the number of corrals between the open door and sheep’s corral. Due to the narrow door, it is allowed just one sheep to leave per minute. In order to let other lazy sheep get fed, Mr. LittleSheep has to move to anther corral to open the door, we assume the distance between the current corral and the destination is D, and the maximum amount of sheep among the rest corrals is M, then it takes D*M minute to move. (Because every step Mr. LittleSheep moves, it takes M minute to calm down the largest group of sheep), Now the question is how Mr. LittleSheep should move to use the least time for feeding all these lazy sheep. Mr. LittleSheep always started his work at 1st corral.

Input
The first line is two integers n, k which indicates the number of corrals and the longest distance which sheep are willing to go.
The second line is n positive integers which describe the amount of sheep in each corral. The ith number a[i] is the number of sheep in ith corral.
(1 <= a[i] <= 10000)(1 <= n <= 2000, 1 <= k <= 500 ,k <= n/2 )

Output
The minimum minutes Mr. LittleSheep should take to feed all sheep.

Sample Input
6 1
4 1 2 3 1 3

Sample Output
21

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 C语言设计一个简单的自动换档程序
    • ¥15 关于logstash转发日志时发生的部分内容丢失问题
    • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。