[LeetCode]Unique Paths
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.
For example, given the array [−2,1,−3,4,−1,2,1,−5,4]
,
the contiguous subarray [4,−1,2,1]
has the largest sum = 6
.
More practice:
If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.
思考:组合数,dp。
class Solution { public: int uniquePaths(int m, int n) { int i,j; int dp[100][100]; memset(dp,0,sizeof(dp)); for(i=0;i<m;i++) { for(j=0;j<n;j++) { if(i==0&&j==0) dp[i][j]=1; else if(i==0) dp[i][j]=dp[i][0]; else if(j==0) dp[i][j]=dp[0][j]; else dp[i][j]=dp[i-1][j]+dp[i][j-1]; } } return dp[m-1][n-1]; } };