Editorial for Facebook Hacker Cup '15 Round 1 P3 - Winning at Sports
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
This problem has a fairly standard dynamic programming formulation:
Let
(we're done!) if (all that's left is for us to finish scoring) otherwise (this victory is not stress-free) (all that's left is for them to finish scoring) if and (this victory is not stress-free) otherwise (either team can score next)
Similarly, let
(we're done!) (all that's left is for us to finish scoring) (this victory is not stressful) if (this victory is not stressful) otherwise (either team can score next)
Obviously, the latter two parameters don't change, so we just need
Comments