給定一個數組A [1:N]。數組的每個元素都是非負的。 允許操作:挑選數組中的兩個元素(兩個元素的值必須至少爲1),並將這兩個元素都減1。這樣我們將獲得1分。什麼是可以賺取的最高點數?如何最大限度地提高總積分?
例子:
A[1:3] = 1 1 2
After step 1: 0 1 1
After step 2: 0 0 0
Maximum points = 2
暴力方法:
total_points <- 0
while value of atleast two elements of A is greater than 0:
subtract 1 from both
total_points <- total_points + 1
return total_points
如何改善的方法?請幫忙。
想想整體總和和最大元素值。 – MBo