题目来源
http://codeforces.com/contest/520/problem/B
题目描述
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
大意是有一台神奇的机器. 机器有一红一绿两个按钮. 机器显示屏上一开始有一个神奇的数字 n, 按一下红色数字就变成 n-1, 按一下蓝色就变成 2*n. n 一开始给定是个正数, 但要是在按按钮的过程中 n<=0, 机器就会”duang”的一下爆炸.
现在给定 n 和要求的数字 m, 要求通过次数最少的按按钮操作把 n 变成 m.
解题思路
一开始下意识地把这道题当成动态规划来做, 即