UVA-11264 - Coin Collector

  • UVa Online Judge 解題結果請於 Submit 後,參閱 uHunt
  • 如果你有任何建議與指教,歡迎於下方留言一起討論喔!
  • 本題選為「20170926 大學程式能力檢定 CPE」題目。

題意概要

假設某個國家流通的硬幣共有 $n$ 種,為了要儘可能的收集最多種不同的硬幣。假設從銀行提領 元,而銀行會按照下列演算法兌換硬幣:

withdraw(X) {
    if (X == 0) return;
    令 Y 為其值不超過 X 且面額最大的硬幣。
    給客戶一個 Y 元的硬幣。
    withdraw(X - Y);
}

本題在不限制金額的前提下,想要在一次提領中兌換到最多種不同的硬幣。


Input

First line of the input contains the number of test cases. Each of the test cases starts with (), the number of different types of coin. Next line contains integers , , . . . , the value of each coin type. . equals to .


Output

For each test case output one line denoting the maximum number of coins that Sultan can collect in a single withdrawal. He can withdraw infinite amount of money from the Bank.


Sample Input

2
6
1 2 4 8 16 32
6
1 3 6 8 15 20

Sample Output

6
4
profile-image
Yung-Sheng Lu
Hello, I'm Yung-Sheng Lu. I am a graduate student in Department of Computer Science at National Chiao Tung University, Taiwan. I am in the Networking and Sensing Systems (NSS) Lab at NCTU.
comments powered by Disqus