编程介的小学生 2019-12-31 17:43 采纳率: 20.5%
浏览 73

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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 buildozer打包kivy app失败
    • ¥30 在vs2022里运行python代码
    • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
    • ¥15 求解 yolo算法问题
    • ¥15 虚拟机打包apk出现错误
    • ¥15 用visual studi code完成html页面
    • ¥15 聚类分析或者python进行数据分析
    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复