Update triangle.cpp

DP code can be simple and effective, when you have it in mind.