algorithm - Minimum number of steps to flip cards deck -


this contest problem not home work.

given n cards facing down, have flip n cards facing up. if flipping ith card then, i-1,i,i+1 flipped. eg: if n = 3, minimum no of steps 1.
given n cards, have calculate minimum no of steps flip cards up.

initially thought kind of fibonacci, let n = 2,3,4 , minimum steps min = 1,1,4 if n = 6, minimum steps 2. struck here, please ?

the cases n=1, 2, , 3 easy.

for n = 3k, easy. flip on k cards starting second one.

for n = 3k+1, first flip both cards on ends, flips on 4 cards. have 3k-3 cards left over, divisible 3, can flipped in k-1 moves.

for n = 3k+2, first choose first card, flips 2 cards. have 3k cards left flip, done in k flips.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -