Tag - dynamic programming in python