Cut Tiles (Large)
Time limit5sMemory limit512 MB
Pack square tiles with power-of-two sides into the fewest MxM tiles using only side-parallel cuts.
- Level
Medium6 of 10
- Topics
- Greedy, Sorting, Bit manipulation
- Solved
- No attempts yet
Problem
Enzo is renovating the house he just bought. The hardest part is buying exactly the right number of tiles. He needs square tiles whose side lengths are in that order. The same size may appear more than once.
The store sells one product only, a square tile of side . Every tile Enzo needs has to be cut out of a tile he bought, and to keep the work simple he only makes cuts parallel to the sides of the tile he is cutting. Each required tile comes out of a single purchased tile in one piece, and cut pieces cannot be joined together.
Find the smallest number of tiles Enzo has to buy.
Input
The first line contains the number of test cases . Each of the next lines holds one test case. A line starts with the number of required tiles and the side length of the tiles on sale. Then come the exponents that give the sizes of the required tiles.
Limits
Output
For each test case, print one line of the form Case #x: y, where is the test case number starting from 1 and is the smallest number of tiles Enzo has to buy.