码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode_62题——Unique Paths (动态规划)

时间:2015-06-02 17:06:01      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:

Unique Paths

 Total Accepted: 45580 Total Submissions: 138958My Submissions

 

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?

技术分享

Above is a 3 x 7 grid. How many possible unique paths are there?

Note: m and n will be at most 100.

 

Hide Tags
 Array Dynamic Programming
 
      这道题比较简单,就是采用动态规划的做法,需要维护一个路径个数的数组,从靠近终点的点开始往前算起就好了
#include<iostream>
#include <vector>
using namespace std;
#define MAXSIZE 110
int uniquePaths(int m, int n) {
	int ary1[MAXSIZE][MAXSIZE];
	ary1[m][n]=1;
	for(int i=m;i>=1;i--)
		for(int j=n;j>=1;j--)
		{
			if(i==m||j==n)
				ary1[i][j]=1;
			else
				ary1[i][j]=ary1[i+1][j]+ary1[i][j+1];
		}
		return ary1[1][1];
}

int main()
{
}

  

leetcode_62题——Unique Paths (动态规划)

标签:

原文地址:http://www.cnblogs.com/yanliang12138/p/4546543.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!