A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
How many possible unique paths are there?
This problem is quite similar with minimum path sum. We just need to change some beginning condition and change the way they calculate paths.
This is a 2 dimensional dp problem. Since the logic of dp in this problem is simple, we can simplify it as we can only use one array to do it.
One thing need to pay attention, if we use vector<>, and give value to them by, for example, dp[i][j] = a. We need to declare its size first. Otherwise we can just use push_back. It will cause segmentation fault if we don't give its size.
No comments:
Post a Comment