#AT1308. D - Match Matching
D - Match Matching
D - 火柴配对
得分:400 分
题目描述
在以下条件下找到能用恰好 N 根火柴棍拼成的最大整数:
- 整数中的每个数字都必须是数字 A1, A2, ..., AM (1 <= Ai <= 9) 中的一个。
- 用于拼成 1、2、3、4、5、6、7、8、9 这 9 个数字所需的火柴棍数量分别为 2、5、5、4、5、6、3、7、6。
约束条件
- 输入的所有值均为整数。
- 2 <= N <= 10^4
- 1 <= M <= 9
- 1 <= Ai <= 9
- Ai 彼此各不相同。
- 存在满足条件的整数可以用恰好 N 根火柴棍拼成。
输入
输入从标准输入中获得,格式如下所示:
N M
A1 A2 ... AM
输出
在题目描述的条件下,打印能用恰好 N 根火柴棍拼成的最大整数。
20 4
3 7 8 4
777773
The integer $777773$ can be formed with $3 + 3 + 3 + 3 + 3 + 5 = 20$ matchsticks, and this is the largest integer that can be formed by $20$ matchsticks under the conditions.
101 9
9 8 7 6 5 4 3 2 1
71111111111111111111111111111111111111111111111111
The output may not fit into a $64$-bit integer type.
15 3
5 4 6
654
相关
在下列比赛中: