a197: Add All
標籤 : Huffman
通過比率 : 30人/38人 ( 79% ) [非即時]
評分方式:
Tolerant

最近更新 : 2021-11-16 14:18

內容

The problem name reflects your task; just add a set of numbers. But you may feel yourselves condescended, to write a  program just to add a set of numbers. Such a problem will simply question your erudition. So, let’s add some flavor of ingenuity to

Addition operation requires cost now, and the cost is the summation of those two to be added. So, to add 1 and 10, you need a cost of11. If you want to add 12 and 3. There are several ways –

 

1 + 2 = 3, cost = 3   

3 + 3 = 6, cost = 6

Total = 9

1 + 3 = 4, cost = 4   

2 + 4 = 6, cost = 6

Total = 10

2 + 3 = 5, cost = 5   

1 + 5 = 6, cost = 6

Total = 11

 

I hope you have understood already your mission, to add a set of integers so that the cost is minimal.

輸入說明

Each test case will start with a positive number, N (2 ≤ N ≤ 5000) followed by N positive integers (all are less than 100000). Input is terminated by a case where the value of N is zero. This case should not be processed.

輸出說明

For each case print the minimum total cost of addition in a single line.

範例輸入 #1
3
1 2 3
4
1 2 3 4
0
範例輸出 #1
9
19
測資資訊:
記憶體限制: 64 MB
公開 測資點#0 (50%): 1.0s , <1K
公開 測資點#1 (50%): 1.0s , <1K
提示 :
標籤:
Huffman
出處:
uva-10954 [管理者: ]


編號 身分 題目 主題 人氣 發表日期
62
super7@gm.oc... (賴麒祐)
a197
python 解題 觀念
138 2023-10-31 00:15