🎯Reach 1 with Fewest Clicks
Turn the counter number X into 1! • Start X = 10 • Buttons: ÷3 (if multiple of 3), ÷2 (if even), −1 Goal: Minimize the button clicks! Define dp[i] as "min clicks to turn i into 1" and fill from small numbers upward.
Loading...
Turn the counter number X into 1! • Start X = 10 • Buttons: ÷3 (if multiple of 3), ÷2 (if even), −1 Goal: Minimize the button clicks! Define dp[i] as "min clicks to turn i into 1" and fill from small numbers upward.
A toy shop has a curious magic counter. Its screen shows an integer X, and there are only three buttons: • 🟦 "÷3" button: usable only when the number is a multiple of 3; divides it by 3. • 🟩 "÷2" button: usable only when the number is even; divides it by 2. • 🟥 "−1" button: subtracts 1 from the number. Reduce the screen to 1 to win candy. But you only win if you pressed the buttons the fewest possible times. Find the minimum number of button clicks to turn X into 1.
10
3
10 → 9(−1) → 3(÷3) → 1(÷3), 3 clicks. Shorter than 10 → 5(−1) → ...
6
2
6 → 2(÷3) → 1(÷2), 2 clicks. (6 → 3(÷2) → 1(÷3) is also 2)