QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 256 MB 満点: 100

#11780. 最优找零问题

統計

在一家 10 美元的商店里,所有商品的价格都在 10 美元或以下。为了更高效地为收银台的顾客服务,需要用最少数量的硬币来找零。

在本题中,你需要针对给定的找零金额,用不同的硬币进行找零。编写一个程序,计算每种面值硬币所需的数量。

输入包含一个金额 $v$、硬币种类数量 $n$ 以及每种硬币的面值 $f_1, f_2, \dots, f_n$。输出是一组数字 $c_1, \dots, c_n$,表示每种硬币所需的数量。找零的方式可能不止一种。金额 $v$ 是一个满足 $0 < v \le 2000$ 的整数,代表需要找零的金额(单位为分)。硬币的面值小于或等于 $10000$。你的程序输出的组合应使用最少数量的硬币。

例如,香港金融管理局发行的港币硬币包括 10 分、20 分、50 分、1 元、2 元、5 元和 10 元,在输入中表示为 $n = 7, f_1 = 10, f_2 = 20, f_3 = 50, f_4 = 100, f_5 = 200, f_6 = 500, f_7 = 1000$。

输入格式

测试数据可能包含多组测试用例,请处理到文件结束。

每个测试用例在一行中包含整数 $v, n, f_1, \dots, f_n$。保证 $n \le 10$ 且 $0 < f_1 < f_2 < \dots < f_n$。

输出格式

输出一行 $n$ 个数字,用空格分隔。如果无法找零,输出单个 $-1$。如果存在多种可能的解,你的程序应输出使用更多低面值硬币的那一种。

样例

样例输入 1

2000 7 10 20 50 100 200 500 1000
250 4 10 20 125 150
35 4 10 20 125 150
48 4 1 8 16 20
40 4 1 10 13 37
43 5 1 2 21 40 80

样例输出 1

0 0 0 0 0 0 2
0 0 2 0
-1
0 1 0 2
3 0 0 1
1 1 0 1 0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.