Saturday, July 10, 2010

SPOJ - JEDNAKOST

Getting back to more programming after an inspirational summer camping trip. Saw one of my friends attempting this problem, thought I should give it a shot.

Recently solved problem #3752 - JEDNAKOS.

If you want to solve the problem yourself - stop reading now.

Solution - Recursion + Memoization

Easy problem really

1) Treat numbers starting with zero as special cases.

2) Let minplus[sum][pos] be an array that is the minimum number of pluses required to obtain the value 'sum' using the postfix starting at 'pos', then it's just simple recursion.

3) To avoid initialization, the array stores the number of pluses plus one.

No comments:

Post a Comment