赞
踩
提示就是思路
n, m = map(int, input().split())
t = list(map(int, input().split()))
t.sort()
loading = [0 for _ in range(len(t))] # 某个人的排队时间等于前一个人的排队时间加上打水时间
for i in range(m, n):
loading[i] = loading[i - m] + t[i - m]
water = [0 for i in range(m)]
for x in range(m):
for y in range(x, len(loading), m):
water[x] += loading[y]
print(sum(water))
这个题没有按照dp来写,我用了递推的方式
因为从下往上走只有向上和向左上两个方向,所以从倒数第二层开始,每一个取下一层的最大值加上自己的值
n = int(input())
mountain = []
for i in range(n):
a = list(map(int,input().split()))
mountain.append(a)
for row in range(n-2,-1,-1):
for col in range(row + 1):
mountain[row][col] = mountain[row][col] + max(mountain[row+1][col],mountain[row+1][col+1])
print(mountain[0][0])
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。