当前位置:网站首页>DP sword finger offer II 100. sum of minimum paths in triangle
DP sword finger offer II 100. sum of minimum paths in triangle
2022-07-26 13:48:00 【Curry won't throw three points】
Catalog
solution 1 Dynamic programming of two-dimensional array
solution 2 Dynamic planning of optimized space
solution 1 Dynamic programming of two-dimensional array
package LeetCode.DP; import java.util.List; public class OfferII100 { public int minimumTotal(List<List<Integer>> triangle) { int length=triangle.size(); int dp[][]= new int [length][length]; //dp[m][n] From 0 0 To m n The shortest distance is dp[m][n] dp[0][0]=triangle.get(0).get(0); for (int i = 1; i <length; i++) { dp[i][0]=dp[i-1][0]+triangle.get(i).get(0);// about d[[i][0] Boundary treatment of for (int j = 1; j <i; j++) { dp[i][j]=Math.min(dp[i-1][j],dp[i-1][j-1])+triangle.get(i).get(j); } dp[i][i]=dp[i-1][i-1]+triangle.get(i).get(i);// about dp[i][i] Boundary treatment of } int min=dp[length-1][0]; for (int i = 0; i < length; i++) { if(min>dp[length-1][i]){ min=dp[length-1][i]; } } return min; } }solution 2 Dynamic planning of optimized space
class Solution { public int minimumTotal(List<List<Integer>> triangle) { int length=triangle.size(); int dp[]=new int[length]; dp[0]=triangle.get(0).get(0); for (int i = 1; i <length; i++) { dp[i]=dp[i-1]+triangle.get(i).get(i); for (int j = i-1; j >0 ; j--) { dp[j]=Math.min(dp[j],dp[j-1])+triangle.get(i).get(j); } dp[0]=dp[0]+triangle.get(i).get(0); } int min=dp[0]; for (int i = 0; i < length; i++) { if (min>dp[i]){ min=dp[i]; } } return min; } }
边栏推荐
- Convert the array in JSON file to struct
- B+ tree index use (8) sorting use and precautions (20)
- 2022-07-26日报:Alphafold DB数据库建立一周年,官推盘点亮点研究
- Photoshop(CC2020)未完
- 【开源之美】nanomsg(2) :req/rep 模式
- Sword finger offer (IX): abnormal jumping steps
- How to build a customer-centric product blueprint: suggestions from the chief technology officer
- Unity中序列化类为json格式
- Completable future practical usage
- 技术分享 | 需要小心配置的 gtid_mode
猜你喜欢

ROS2学习(1)ROS2简述

The serialization class in unity is in JSON format

Solve the problem that the remote host cannot connect to the MySQL database

Why does WPS refuse advertising?

算法--连续数列(Kotlin)

重押海外:阿里、京东、顺丰再拼“内力”

Comparison between SIGMOD function and softmax function

Unicode file parsing methods and existing problems

Code cloud, which officially supports the pages function, can deploy static pages

时间复杂度和空间复杂度
随机推荐
Unicode file parsing methods and existing problems
[turn] judge the relationship between two geometries in ArcGIS
Photoshop(CC2020)未完
SuperMap iclient for leaflet loads Gauss Kruger projection three-dimensional zonation CGCS2000 geodetic coordinate system WMTs service
[oauth2] v. oauth2loginauthenticationfilter
Abstract factory and its improvement examples
B+ tree index uses (7) matching column prefix, matching value range (19)
Analysis on the current situation and optimization strategy of customer experience management in banking industry
Completable future practical usage
Time complexity analysis of bubble sorting
B+ tree (4) joint index -- MySQL from entry to proficiency (16)
消息的订阅和发布
Docker swarm cluster builds highly available MySQL active and standby
Huawei computer test ~ offset realizes string encryption
Win11+VS2019配置YOLOX
循环队列(c语言实现)
flutter多渠道打包运行
Algorithm -- continuous sequence (kotlin)
Canvas upload image Base64 with cropping function jcrop.js
The.Net webapi uses groupname to group controllers to render the swagger UI


