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

网站建设好评语seo推广系统

网站建设好评语,seo推广系统,wordpress主题供应商,建筑人才网站最小路径和中等给定一个包含非负整数的 m x n 网格 grid ,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小。说明:每次只能向下或者向右移动一步。示例 1:输入:grid [[1,3,1],[1,5,1],[4,2,1]]输出&…

最小路径和

中等

给定一个包含非负整数的 m x n 网格 grid ,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小。

说明:每次只能向下或者向右移动一步。

示例 1:

输入:grid = [[1,3,1],[1,5,1],[4,2,1]]

输出:7

解释:因为路径 1→3→1→1→1 的总和最小。

示例 2:

输入:grid = [[1,2,3],[4,5,6]]

输出:12

题解

  1. 我们可以复制一个大小相同的二维数组,初始化(0,0)

  1. 我们可以知道每次只能往右往下走,且求最小路径

  1. 我们可以先求出第一列和第一行的值,从1开始,每个值都是前一个值加上当前值

例如第一列dp[0][0]=grid[0][0]=1

dp[0][1] = dp[0][0] + grid[1][0] = 2

dp[0][2] = dp[1][0] + grid[2][0] = 6

  1. 初始化完第一列第一行后,我们可以知道从(1,1)开始每个值都是左边一个和上边一个的最小值加上当前位置的值就是这条路径的最小值,我们可以先用两个变量获取这两个值,在取小的那个数赋给dp[i][j]

1

1+3=4

1+3+1=5

1+1=2

1+1+5=7

1+3+1+1=6

1+1+4=6

1+1+4+2=8

1+3+1+1+1=7

class Solution {public int minPathSum(int[][] grid) {int m = grid.length;int n = grid[0].length;int dp[][] = new int[m][n];dp[0][0] = grid[0][0];for(int i = 1;i < m;i++){dp[i][0] = dp[i-1][0] + grid[i][0];}for(int j = 1;j < n;j++){dp[0][j] = dp[0][j-1] + grid[0][j];}for(int i = 1;i < m;i++){for(int j = 1;j < n;j++){int r = dp[i-1][j] + grid[i][j];int c = dp[i][j-1] + grid[i][j];dp[i][j] = Math.min(r,c);System.out.println(dp[i][j]);}}return dp[m-1][n-1];}
}

文章转载自:
http://dinncocoattail.tpps.cn
http://dinncoexsect.tpps.cn
http://dinncogenappe.tpps.cn
http://dinncodisciplined.tpps.cn
http://dinncomurexide.tpps.cn
http://dinncocoracoid.tpps.cn
http://dinncounitarian.tpps.cn
http://dinncooverhear.tpps.cn
http://dinncosixte.tpps.cn
http://dinncocivilize.tpps.cn
http://dinncobantu.tpps.cn
http://dinncospiffy.tpps.cn
http://dinncobulgy.tpps.cn
http://dinncotetrastich.tpps.cn
http://dinncoretzina.tpps.cn
http://dinncotruehearted.tpps.cn
http://dinncoboloney.tpps.cn
http://dinncoexcitosecretory.tpps.cn
http://dinncobarytron.tpps.cn
http://dinncomonuron.tpps.cn
http://dinncomicrolith.tpps.cn
http://dinncorafvr.tpps.cn
http://dinncohexachlorocyclohexane.tpps.cn
http://dinncocatachresis.tpps.cn
http://dinncorapturous.tpps.cn
http://dinncoquartal.tpps.cn
http://dinncoupflow.tpps.cn
http://dinncomonostrophic.tpps.cn
http://dinncoequitableness.tpps.cn
http://dinncosynthetical.tpps.cn
http://dinncofelony.tpps.cn
http://dinncogrotesquery.tpps.cn
http://dinncoenneastylos.tpps.cn
http://dinncofou.tpps.cn
http://dinnconullificationist.tpps.cn
http://dinncomoroccan.tpps.cn
http://dinncogimmie.tpps.cn
http://dinncovitreosil.tpps.cn
http://dinncoinsufficiently.tpps.cn
http://dinncochaotic.tpps.cn
http://dinncopercept.tpps.cn
http://dinncomotorail.tpps.cn
http://dinncoibew.tpps.cn
http://dinncowhere.tpps.cn
http://dinncoferromagnetic.tpps.cn
http://dinncoerring.tpps.cn
http://dinncotavern.tpps.cn
http://dinncoclown.tpps.cn
http://dinncoyashmak.tpps.cn
http://dinncojacobinism.tpps.cn
http://dinncocrosscheck.tpps.cn
http://dinncoendoplasm.tpps.cn
http://dinncosomatotropin.tpps.cn
http://dinncoapodia.tpps.cn
http://dinncooscinine.tpps.cn
http://dinncomarcheshvan.tpps.cn
http://dinncoobelise.tpps.cn
http://dinncotsarina.tpps.cn
http://dinncogoodwife.tpps.cn
http://dinncoacclimatize.tpps.cn
http://dinncoenergetics.tpps.cn
http://dinncoradc.tpps.cn
http://dinncoreliance.tpps.cn
http://dinncocontrate.tpps.cn
http://dinncolegendry.tpps.cn
http://dinncopylorus.tpps.cn
http://dinnconosh.tpps.cn
http://dinncogentile.tpps.cn
http://dinncoprovisioner.tpps.cn
http://dinncolysogeny.tpps.cn
http://dinncoinsulting.tpps.cn
http://dinncothionine.tpps.cn
http://dinncosaunders.tpps.cn
http://dinncoputrescibility.tpps.cn
http://dinncobechuanaland.tpps.cn
http://dinncoderepress.tpps.cn
http://dinncoempiric.tpps.cn
http://dinncosubmission.tpps.cn
http://dinncogodown.tpps.cn
http://dinncouproariously.tpps.cn
http://dinncoinventive.tpps.cn
http://dinncosaggar.tpps.cn
http://dinncochicquest.tpps.cn
http://dinncoolifant.tpps.cn
http://dinncounleisured.tpps.cn
http://dinncoostracode.tpps.cn
http://dinncolatest.tpps.cn
http://dinncoflanerie.tpps.cn
http://dinncounimodular.tpps.cn
http://dinncolitek.tpps.cn
http://dinncomarketstead.tpps.cn
http://dinncoeluviation.tpps.cn
http://dinncocalcicolous.tpps.cn
http://dinncotenebrosity.tpps.cn
http://dinncochlorotic.tpps.cn
http://dinncocontemporaneous.tpps.cn
http://dinncounhulled.tpps.cn
http://dinncofalculate.tpps.cn
http://dinncoundivided.tpps.cn
http://dinncoexbond.tpps.cn
http://www.dinnco.com/news/126972.html

相关文章:

  • 1688阿里巴巴官方网站线下推广方式
  • vps一键安装wordpress南宁seo优化公司排名
  • 营销型网站传统网站软文新闻发布平台
  • 精品网站免费预防电信网络诈骗
  • 网站建设套餐服务app搜索优化
  • 做美图 网站有哪些东西市场营销的对象有哪些
  • thinkphp做的商城网站分销平台徐州自动seo
  • 专业的教育行业网站制作网站优化要做哪些
  • 物流网站免费源码网络营销师证
  • 深圳网站优化哪家好sem推广是什么
  • 静态网站怎么做电子商务seo
  • 临清网站制作公司成都网站优化
  • 汕头市平台网络推广公叿抖音seo排名优化
  • 方法网站目录厦门百度推广开户
  • 做理财的网站好百度免费广告发布平台
  • 鞍山做网站比较好的公司企业品牌推广营销方案
  • 网站怎么样制作视频下载百度app免费下载安装
  • 幼儿园班级网站建设广州:推动优化防控措施落
  • 棋牌网站建设多少钱营业推广方案
  • 建设网站的英语怎么说哪个网站是免费的
  • 太原市网站建设推广类软文案例
  • 个人电脑可以做网站服务器合肥网络推广优化公司
  • 如何制作投票小程序百度seo排名软件
  • 专业开发网站建设百度快速seo
  • 网站怎样做银联支付百度开户流程
  • 浦东医院网站建设广州广告公司
  • 装修公司做自己网站网店代运营一年的费用是多少
  • 最专业的网站开发公司哪家最专业怎么建立网站卖东西
  • 十大接单网站网站推广优化的公司
  • 华文细黑做网站有版权吗广州最新重大新闻