Nowhere Money
Time limit1sMemory limit128 MB
Represent each amount as a sum of T(s) values (T(n) = Fibonacci-like count) with the fewest slots whose sizes differ by at least 2, and print the sizes and values.
- Level
Medium6 of 10
- Topics
- Greedy, Dynamic programming, Math, Implementation
- Solved
- No attempts yet
Problem
In the town of Nowhere, money is made of coins and slots. There are two kinds of coins: size-1 and size-2. A size-2 coin is exactly twice as thick as a size-1 coin. People stack coins inside a slot and use the filled slot as money.
Slots come in many sizes. A slot of size can hold a stack of coins whose total thickness equals that of size-1 coins. Only a completely filled slot counts as valid money.
The value of a filled slot is the number of distinct ways it can be filled with coins. For example:
- A size-1 slot has only way: a single size-1 coin.
- A size-2 slot has ways: two size-1 coins, or one size-2 coin.
- A size-5 slot has ways:
1 1 1 1 1,1 1 1 2,1 1 2 1,1 2 1 1,2 1 1 1,1 2 2,2 1 2,2 2 1.
So a filled size-1, size-2, and size-5 slot is worth , , and monetary units respectively (the value depends only on the slot size, not on which coins are used or how they are arranged). Write for the value of a filled slot of size .
Mr. Thinktwice runs a grocery store. He noticed that customers prefer shops that hand back change in a convenient form, and from a small survey he learned that customers want their change built from slots under two rules:
- The number of slots is as small as possible.
- Every two slot sizes differ by at least , so no two slots are the same size or adjacent sizes; this makes the slots easy to tell apart.
For a given amount of change, output a series of slot sizes that satisfies these rules, sorted in descending order. Every amount of change can be written as
where
- is the amount of change,
- is the number of slots,
- is the size of the -th slot,
- maps a slot size to its value (the number of distinct ways to fill it), and
- means .
For example:
Input
The input contains several amounts of change, one per line. Each amount is a positive integer not greater than . Input ends at end-of-file (EOF).
Output
For each amount of change, print four lines:
- the amount of change itself;
- the slot sizes in descending order, separated by single spaces (every slot size is at most );
- the corresponding slot values, in the same order, separated by single spaces;
- a blank line.