#P1021. Postage Stamp Problem
Postage Stamp Problem
Postage Stamp Problem
Given an envelope that can accept at most (N) stamps and (K) different stamp denominations (with unlimited supply of each), design the stamp denominations to maximize (\mathsf{MAX}) such that every postage value from (1) to (\mathsf{MAX}) can be formed using no more than (N) stamps.
For example, when (N=3) and (K=2), if the stamp denominations are (1) and (4), every postage value from (1) to (6) is achievable (in addition to values like (8), (9) and (12)). However, if the denominations are (1) and (3), every value from (1) to (7) can be formed. Hence, the maximum continuous postage is (\mathsf{MAX}=7) with denominations (1) and (3).
inputFormat
The input consists of two integers (N) and (K) (with (N+K \le 15)) separated by spaces.
outputFormat
Output the maximum continuous postage value (\mathsf{MAX}) on the first line and the chosen stamp denominations (in increasing order) on the second line, separated by spaces.
sample
3 2
7
1 3
</p>