Simple Programm using dynamic programming