dint solve(int X, int Y){
if (X==Y) return 1;
if (X>Y) return solve(X-Y, Y) + 1;
return solve(X, Y-X) + 1;
}
N@picsel
no it isn't.
AAAAA
AAAAA
AAAAA
AAAAA
AAAAA
BCDEF
the answer is 6 :)
pAAABB
AAABB
AAACC
DDDCC
DDDFF
DDDFF
Nups, i'm sorry, you're right, i never looked at it that way :)
dI solved it, using dynamic programming, and the fact that when you form the square containing the lower right corner, one of the 2 curs you introduce (for the 2 "internal sides" of it) has to go on until it touches the edges of the big retangle. However, I don't know why this is true. Any reasoning / proof on this?
Thanks
rI don't have a proof but a counterexample:
11x13. Your algorithm gives 8.
Right answer is: 6
AAAACCCCFFFFF
AAAACCCCFFFFF
AAAACCCCFFFFF
AAAACCCCFFFFF
BBBBBBBDFFFFF
BBBBBBBEEEEEE
BBBBBBBEEEEEE
BBBBBBBEEEEEE
BBBBBBBEEEEEE
BBBBBBBEEEEEE
BBBBBBBEEEEEE