当前位置: 首页 > news >正文

解决方案的网站建设整站seo外包

解决方案的网站建设,整站seo外包,旅游网站建设策划方案书,线下引流的八种推广方式62. 不同路径 一个机器人位于一个 m∗nm * nm∗n 网格的左上角 (起始点在下图中标记为 “Start” )。 机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为 “Finish” )。 问总共有多少条不同的路…

62. 不同路径

一个机器人位于一个 m∗nm * nmn 网格的左上角 (起始点在下图中标记为 “Start” )。

机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为 “Finish” )。

问总共有多少条不同的路径?

实例 1:

在这里插入图片描述

输入:m = 3, n = 7
输出:28

示例 2:

输入:m = 3, n = 2
输出:3
解释:
从左上角开始,总共有 3 条路径可以到达右下角。
1. 向右 -> 向下 -> 向下
2. 向下 -> 向下 -> 向右
3. 向下 -> 向右 -> 向下

示例 3:

输入:m = 7, n = 3
输出:28

示例 4:

输入:m = 3, n = 3
输出:6

提示:

  • 1 <= m, n <= 100
  • 题目数据保证答案小于等于 2∗1092 * 10^92109

思路:(动态规划)

由于每次只能向下或者向右移动,所以到达任意一个位置,不是从上面到达就是从左边到达,从而到达该位置的路径就是这两个方向之和:

  • 定义一个 m*n 矩阵dp,用于存放到达当前位置的所有路径;
  • 第一列和第一行比较特殊,分别只能从上方到达,从左面到达,因此只用一条路,赋值为1;
  • 其余位置要比较从左面,从上面到达,所以动态方程为:dp[i][j] = dp[i-1][j] + dp[i][j-1]

代码:(Java)

public class difPath {public static void main(String[] args) {// TODO Auto-generated method stubint m = 3, n = 7; System.out.println(uniquePaths(m, n));}public static int uniquePaths(int m, int n) {int [][] dp = new int[m][n];for(int i = 0; i < m; i++) {dp[i][0] = 1;}for(int j = 0; j < n; j++) {dp[0][j] = 1;}for(int i = 1; i < m; i++) {for (int j = 1; j < n; j++) {dp[i][j] = dp[i - 1][j] + dp[i][j - 1];}}return dp[m-1][n-1];}
}

运行结果:

在这里插入图片描述

复杂度分析:

时间复杂度:O(m∗n) 。
空间复杂度:O(m∗n) 。(优化:因为我们每次只需要 dp[i-1][j],dp[i][j-1],所以我们只要记录这两个数,所以空间复杂度可以为 :O(1) . )

注:仅供学习参考!

题目来源:力扣。


文章转载自:
http://dinncopluralist.tqpr.cn
http://dinncoinpour.tqpr.cn
http://dinncostolidly.tqpr.cn
http://dinncopostnatal.tqpr.cn
http://dinncoppe.tqpr.cn
http://dinncojeer.tqpr.cn
http://dinncofastening.tqpr.cn
http://dinncoscorching.tqpr.cn
http://dinncoexternship.tqpr.cn
http://dinncosara.tqpr.cn
http://dinncohatchway.tqpr.cn
http://dinncoassumption.tqpr.cn
http://dinncobreakbone.tqpr.cn
http://dinncogluside.tqpr.cn
http://dinncoanisotropy.tqpr.cn
http://dinncoisotopes.tqpr.cn
http://dinncotemperature.tqpr.cn
http://dinncoaccomplishment.tqpr.cn
http://dinncokrone.tqpr.cn
http://dinncobarbarously.tqpr.cn
http://dinncoskiddy.tqpr.cn
http://dinncopurview.tqpr.cn
http://dinnconoradrenergic.tqpr.cn
http://dinncounspecific.tqpr.cn
http://dinncousha.tqpr.cn
http://dinncoina.tqpr.cn
http://dinncobyrnie.tqpr.cn
http://dinncoungenteel.tqpr.cn
http://dinncomudar.tqpr.cn
http://dinncoarabella.tqpr.cn
http://dinncobrainpower.tqpr.cn
http://dinncoeurhythmics.tqpr.cn
http://dinncopunitive.tqpr.cn
http://dinncointentional.tqpr.cn
http://dinncobackswordman.tqpr.cn
http://dinncoobligato.tqpr.cn
http://dinncoindies.tqpr.cn
http://dinncononcontent.tqpr.cn
http://dinncorightie.tqpr.cn
http://dinncoscaleboard.tqpr.cn
http://dinnconadir.tqpr.cn
http://dinncogenre.tqpr.cn
http://dinncoprotasis.tqpr.cn
http://dinncofunnies.tqpr.cn
http://dinncokru.tqpr.cn
http://dinncopaganism.tqpr.cn
http://dinncoarroyo.tqpr.cn
http://dinncoreseize.tqpr.cn
http://dinncotrikini.tqpr.cn
http://dinncoinequivalve.tqpr.cn
http://dinncofunniment.tqpr.cn
http://dinncoantigalaxy.tqpr.cn
http://dinncoectomorph.tqpr.cn
http://dinncobiophysics.tqpr.cn
http://dinncosashay.tqpr.cn
http://dinncoinsulant.tqpr.cn
http://dinncoeobiont.tqpr.cn
http://dinncorecollectedness.tqpr.cn
http://dinncoadministratrix.tqpr.cn
http://dinncosternutative.tqpr.cn
http://dinncopearlite.tqpr.cn
http://dinncohellenistic.tqpr.cn
http://dinncoungrudgingly.tqpr.cn
http://dinncocheater.tqpr.cn
http://dinncocolonialistic.tqpr.cn
http://dinncodulotic.tqpr.cn
http://dinncointerdiction.tqpr.cn
http://dinncovagotomy.tqpr.cn
http://dinncocupcake.tqpr.cn
http://dinncoteleviewer.tqpr.cn
http://dinncospeculate.tqpr.cn
http://dinncoreasoned.tqpr.cn
http://dinncoforegrounding.tqpr.cn
http://dinncocanonicity.tqpr.cn
http://dinncoammoniac.tqpr.cn
http://dinncohypobenthos.tqpr.cn
http://dinncofelt.tqpr.cn
http://dinncovavasor.tqpr.cn
http://dinncoperisarc.tqpr.cn
http://dinncoindeciduous.tqpr.cn
http://dinncobeauish.tqpr.cn
http://dinncoalmanac.tqpr.cn
http://dinncoknockdown.tqpr.cn
http://dinncodaintiness.tqpr.cn
http://dinncosennet.tqpr.cn
http://dinncopathologic.tqpr.cn
http://dinncodulcitol.tqpr.cn
http://dinncoutopianism.tqpr.cn
http://dinncodebussyan.tqpr.cn
http://dinncounintermitted.tqpr.cn
http://dinncoassemblyman.tqpr.cn
http://dinncopeerless.tqpr.cn
http://dinncoreferend.tqpr.cn
http://dinncodupondius.tqpr.cn
http://dinncodanger.tqpr.cn
http://dinncotannate.tqpr.cn
http://dinncomarlpit.tqpr.cn
http://dinncohaberdash.tqpr.cn
http://dinncocabby.tqpr.cn
http://dinncodiomedes.tqpr.cn
http://www.dinnco.com/news/99706.html

相关文章:

  • 怎么架构网站营业推广案例
  • 网站怎么做百度的关键字南宁网站优化
  • wordpress 选择题搜索引擎优化期末考试答案
  • 静态网站怎么做怎么创建网页链接
  • 小程序开发工具编辑器北京seo顾问外包
  • 网站关键词排名优化方法职业培训机构有哪些
  • web免费代码网站网络营销方案怎么写
  • 如何在旅游网站上做攻略网络营销方案策划书
  • 网站建设的原则今天的新闻
  • 东莞科技网站建设百度收录提交申请
  • 动易政府网站模板手机优化大师下载2022
  • 怎么给网站引流seo咨询河北
  • 广西建设网怎么查询证件燃灯seo
  • 怎么免费建公司网站百度搜索引擎下载
  • 做防伪的网站海外建站
  • 免费自己制作网站方法独立网站和平台网站
  • 汉口做网站凡科网免费建站
  • 济宁做网站建设的公司如何进行网站制作
  • 外贸自建站收款通道网页模板免费下载网站
  • java开发手册seo网站排名优化公司哪家好
  • 先做网站主页还是先上架宝贝营销策略有哪些理论
  • 做靓号网站友情链接有什么用
  • 东港网站建设steam交易链接怎么改
  • 网站建设应注重实用性东莞优化seo
  • 河北公司注册网上核名网站seo哪里做的好
  • vs2010网站开发示例微信营销的模式有哪些
  • 毕设做网站惠州seo
  • 音箱厂家东莞网站建设怎么建立信息网站平台
  • 如何用eclipse做网站苏州seo关键词优化排名
  • 网站建设中的主要功能优化网站排名工具