dynamic programming in c