标题:[没人气,抄道题] 分糖果
取消只看楼主
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
结帖率:91.67%
已结贴  问题点数:100 回复次数:1 
[没人气,抄道题] 分糖果
There are N children standing in a line. Each child is assigned a rating value.
You are giving candies to these children subjected to the following requirements:
    Each child must have at least one candy.
    Children with a higher rating get more candies than their neighbors.
What is the minimum candies you must give?
n个小孩站一排,每个小孩有一个等级值。现在分发糖果给他们,要求:
a. 每个小孩至少分到一颗糖。
b. 等级高的小孩要比靠近他的低等级小孩拿到的糖果多。
请计算最少需要多少糖果

例如6个小孩,等级分别是 1, 3, 7, 5, 3, 2
那么糖果得这样分才最少:1, 2, 4, 3, 2, 1
即对于 { 1, 3, 7, 5, 3, 2 } 这个数列,结果为 13
搜索更多相关主题的帖子: following children Children assigned minimum 
2015-08-06 12:59
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:0 
回复 2楼 wp231957
是的
2015-08-06 14:19



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-456149-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017760 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved