思路:
贪心。
实现:
1 class Solution 2 { 3 public: 4 int minMoves(int target, int maxDoubles) 5 { 6 int res = 0, d = 0; 7 while (target != 1) 8 { 9 if (target & 1) { res++; target--; } 10 else 11 { 12 if (d < maxDoubles) { target >>= 1; res++; d++; } 13 else { res += target - 1; break; } 14 } 15 } 16 return res; 17 } 18 };