optimize DP solution for unique path