当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3704:Gem Combining

题目描述
In the game "Gem Craft", we create gems in the item bar.
There are N grids in the item bar, each grid can only accomodate one gem.
Each gem has its level.
When the level of a gem upgrade by 1, the power of the gem will be doubled.
The key to win the game is to get a high level gem.
Gems with level 0 are available directly.
To get gems with higher level, the only way is to combine low level gems.
Suppose we have 2*N gems with level K now, they can be turned into N gems with level (K+1) afert a combining operation.
Your task is to get at least one gem with level M in minimum steps of operation.
For one step of operation, you can do one of the following two things:
(1) Get gems with level 0 directly, filling up the empty grids.
(2) Combine even number of gems with same level.
输入解释
The input contain some test cases.
Each test case contains two integers N and M (1<=N<=36, 0<=M<=20).
The input ends when N=M=0, this test case doesn't need processing.
输出解释
For each test case, output one line.
The line contains only one integer, the minimum steps of operation.
If there is no solution to get a gem with level M, output -1 instead.
输入样例
4 3
8 3
0 0
输出样例
9
4

提示
We use dots to present empty grid, use number to present the level of a gem.

The first sample can be solved like this:

****        Initial
0000        Get level 0 gems
**11        Combine level 0 gems
***2        Combine level 1 gems
0002        Get level 0 gems
*012        Combine level 0 gems
0012        Get level 0 gems
*112        Combine level 0 gems
**22        Combine level 1 gems
***3        Combine level 2 gems

In total of 9 steps of operation.

The second sample can be solved like this:

********        Initial
00000000        Get level 0 gems
****1111        Combine level 0 gems
******22        Combine level 1 gems
*******3        Combine level 2 gems

It only takes 4 steps of operation.
来自杭电HDUOJ的附加信息
Author YY & LMY @ FDU
Recommend lcy

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-3704

最后修改于 2020-10-25T23:06:13+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 32768/32768K(Java/Others)