Reslan's blog

By Reslan, history, 10 years ago, In English

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

  • Vote: I like it
  • +4
  • Vote: I do not like it

»
10 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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!