Triangle Problem using Dynamic Programming in PHP/Python and C