Hello codeforces
How to solve this problem
in the tutorial it was mentioned that this problem can be solved using DP
but I'm really confused hot how can I maximize the number of trailing zeroes
thank in advance
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3676 |
| 2 | Kevin114514 | 3657 |
| 3 | jiangly | 3638 |
| 4 | turmax | 3442 |
| 5 | tourist | 3380 |
| 6 | Um_nik | 3353 |
| 7 | strapple | 3350 |
| 8 | squareOf105 | 3346 |
| 9 | heuristica | 3322 |
| 10 | maroonrk | 3310 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 158 |
| 2 | nik_exists | 150 |
| 2 | maspy | 150 |
| 4 | AmShZ | 143 |
| 4 | Um_nik | 143 |
| 6 | Errichto | 139 |
| 7 | adamant | 137 |
| 8 | BledDest | 134 |
| 9 | maroonrk | 133 |
| 10 | qwexd | 130 |
Hello codeforces
How to solve this problem
in the tutorial it was mentioned that this problem can be solved using DP
but I'm really confused hot how can I maximize the number of trailing zeroes
thank in advance
| Name |
|---|



Good day to you!
At first lets "transform/clarify" the statement a little-bit:
To find number of trailing zeroes in base-6, you have to find MINIMUM of "2" and "3" in factorization.
So you have N*M grid, you are on [0][0] corner and want to get to [?][M] /or/ [N][?], while maximizing the minimum of "2/3"
You know that you will travel through max 200 numbers < 2^10, meaning, that you can meet at most "200*9" two's (and offcourse less threes).
So now you are at [X][Y] and you can expand to [X+1][Y] /OR/ [X][Y+1]
You can also "REMEMBER" the number of "3" and number of "2" until now.
So first (more easier) lets have dynamic [N][M][1800][1200].
Now you can expand to [X+1][Y] / [Y][X+1], returning MAXIMUM {lets think about it recursively}, and whenever you reach "N" or "M", you return minimum(2s,3s).
In every node, lets have the number "factorized" to "2s" and "3s" — and with all expansions, add the number of "2s" / "3s".
Hope it is a little-bit clear (till now).
Anyway as you can see, 100*100*1800*1200 is too much, so what to do with this?
Well — a little trick — you know, that if you have "A+c 2s" and "A 3s" (or vice versa), you can expand (instead of [X][Y][A+c][A]) to ([X][Y][c][0]+c) [because you will always get result of "c" here]
YAY! This means, that you will NEVER have to store both [2s] and [3s] at one moment! {the second will be always 0}
So we can go with [N][M][1800][BOOL], where bool will tell us, whether we are actually storing 2s or 3s
The complexity will be N*M*1800*2 (since there is no other overhead).
I'm sorry (I'm not best at explaining) — hope you took at least a little "something" from it :P
Good Luck & Have nice day!