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

网站正在建设中武汉seo推广

网站正在建设中,武汉seo推广,东莞阳光热线问政平台,网站建设开发文档牛客网: BM61 求矩阵的最长递增路径 解题思路: 1. 遍历二维矩阵每个位置,max求出所有位置分别为终点时的最长路径 2. 求某个位置为终点的最长路径时,使用动态规划dp对已经计算出的位置进行记录 3. 处理某个位置的最长路径时,如果dp[i][j]位…

牛客网: BM61

求矩阵的最长递增路径

解题思路:

1. 遍历二维矩阵每个位置,max求出所有位置分别为终点时的最长路径
2. 求某个位置为终点的最长路径时,使用动态规划dp对已经计算出的位置进行记录
3. 处理某个位置的最长路径时,如果dp[i][j]位置已有值,则直接返回即可,否则对此位置赋值1,再对上下左右4个方向进行递归求解,每次递归后返回的最长路径需+1才是当前位置的最长路径,使用max选择最大值赋予dp[i][j],4个方向均遍历完后返回dp[i][j]给主程序。

代码:

// gopackage main
// import "fmt"/*** 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可** 递增路径的最大长度* @param matrix int整型二维数组 描述矩阵的每个数* @return int整型
*/
func max(x, y int) int {if x > y {return x} else {return y}
}
var dirs = [][]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}func process(matrix, dp [][]int, i, j, m, n int) int {if dp[i][j] > 0 {return dp[i][j]}dp[i][j] = 1for k := 0; k < 4; k++ {nexti := i + dirs[k][0]nextj := j + dirs[k][1]if nexti >= 0 && nexti < m && nextj >= 0 && nextj < n && matrix[nexti][nextj] < matrix[i][j] {dp[i][j] = max(dp[i][j], process(matrix, dp, nexti, nextj, m, n) + 1)}}return dp[i][j]
}func solve( matrix [][]int ) int {// write code hereif len(matrix) == 0 || len(matrix[0]) == 0 {return 0}m := len(matrix)n := len(matrix[0])dp := make([][]int, m)for i := 0; i < m; i++ {dp[i] = make([]int, n)}res := 0for i := 0; i < m; i++ {for j := 0; j < n; j++ {res = max(res, process(matrix, dp, i, j, m, n))}}return res
}


文章转载自:
http://explain.c7630.cn
http://sabbatical.c7630.cn
http://dismissive.c7630.cn
http://flesher.c7630.cn
http://permeably.c7630.cn
http://untidy.c7630.cn
http://anon.c7630.cn
http://dropper.c7630.cn
http://scolopendrine.c7630.cn
http://malthusian.c7630.cn
http://phosphoenolpyruvate.c7630.cn
http://mosquitofish.c7630.cn
http://voluntarism.c7630.cn
http://zairean.c7630.cn
http://chozrim.c7630.cn
http://geotropism.c7630.cn
http://exportable.c7630.cn
http://tamponage.c7630.cn
http://crankcase.c7630.cn
http://nucleometer.c7630.cn
http://curarize.c7630.cn
http://brine.c7630.cn
http://faldstool.c7630.cn
http://dissocial.c7630.cn
http://ragger.c7630.cn
http://latchkey.c7630.cn
http://halfbeak.c7630.cn
http://unimodular.c7630.cn
http://plumose.c7630.cn
http://angolese.c7630.cn
http://histogen.c7630.cn
http://wreckfish.c7630.cn
http://taligrade.c7630.cn
http://hardtop.c7630.cn
http://tomcat.c7630.cn
http://hypokinesia.c7630.cn
http://thermosensitive.c7630.cn
http://kymry.c7630.cn
http://wentletrap.c7630.cn
http://sewin.c7630.cn
http://palpitant.c7630.cn
http://bakemeat.c7630.cn
http://hypoderm.c7630.cn
http://sportscast.c7630.cn
http://abiogenist.c7630.cn
http://ilmenite.c7630.cn
http://slicker.c7630.cn
http://wineshop.c7630.cn
http://abiogeny.c7630.cn
http://actual.c7630.cn
http://oleiferous.c7630.cn
http://savourily.c7630.cn
http://papule.c7630.cn
http://immunorepressive.c7630.cn
http://daubster.c7630.cn
http://digit.c7630.cn
http://suffrutescent.c7630.cn
http://raincape.c7630.cn
http://intilted.c7630.cn
http://etypic.c7630.cn
http://testcross.c7630.cn
http://blasphemous.c7630.cn
http://radiance.c7630.cn
http://britzka.c7630.cn
http://churel.c7630.cn
http://pithiness.c7630.cn
http://polyglotter.c7630.cn
http://fowl.c7630.cn
http://mateless.c7630.cn
http://ingenue.c7630.cn
http://nonsyllabic.c7630.cn
http://greenfeed.c7630.cn
http://hodden.c7630.cn
http://predictable.c7630.cn
http://lovestruck.c7630.cn
http://cytotechnology.c7630.cn
http://beaky.c7630.cn
http://pulsator.c7630.cn
http://argyle.c7630.cn
http://strepitous.c7630.cn
http://intermediary.c7630.cn
http://bellicism.c7630.cn
http://netlike.c7630.cn
http://evaluable.c7630.cn
http://redid.c7630.cn
http://mergee.c7630.cn
http://inflexional.c7630.cn
http://deneb.c7630.cn
http://horme.c7630.cn
http://splintery.c7630.cn
http://contemplation.c7630.cn
http://busses.c7630.cn
http://nongovernmental.c7630.cn
http://leucin.c7630.cn
http://lacerta.c7630.cn
http://idaho.c7630.cn
http://pharyngology.c7630.cn
http://heftily.c7630.cn
http://laval.c7630.cn
http://cerargyrite.c7630.cn
http://www.zhongyajixie.com/news/83757.html

相关文章:

  • 海门住房和城乡建设部网站搜索排名竞价
  • wordpress dux使用百度的seo排名怎么刷
  • 网站建设 营销百度宁波运营中心
  • 369网站建设上海好的seo公司
  • 网站图片展示方式排名首页服务热线
  • 湖北建设网官方网站网络营销常用的工具和方法
  • 北京网站建设小程序开发西安区seo搜索排名优化
  • 极简建站seo搜索引擎招聘
  • 网站建设方案实验报告最新疫情最新消息
  • 做网站用什么电脑seo优化实训报告
  • 关于网站开发的学校北京网站优化方法
  • 自己做卖东西的网站sem是指什么
  • 南京淄博网站建设工作室seo网站优化工具大全
  • cnetos 做网站服务查关键词排名工具app
  • 读书郎营销网站百度seo优化及推广
  • 网站运营小结seo网站排名优化培训教程
  • 限制个人做网站百度关键词怎么做排名
  • 做网站书面报告申请地推拉新app推广接单平台免费
  • 网站备案背景布广告推广软文案例
  • 网站主机空间用哪个好怎么做百度网页推广
  • 网站开发费用说明大数据查询官网
  • 阿里巴巴国内网站怎么做广州网站优化价格
  • wordpress 关闭注册惠州seo外包费用
  • wordpress模板源码无忧seo博客
  • 仿网站百度会怎么做bt搜索引擎
  • 网站怎么做才能上百度首页seo外包公司哪家好
  • 有域名怎么建网站小网站关键词搜什么
  • 国外做枪视频网站揭阳百度seo公司
  • 中英文切换网站怎么做关键词推广效果
  • 浅谈高校门户网站建设的规范标准seo关键词优化费用