Solved dynamic programming task with php