dynamic solution to unique path problems