当前位置:网站首页>[leetcode refers to offer 47. Maximum value of gift (medium)]
[leetcode refers to offer 47. Maximum value of gift (medium)]
2022-04-23 21:21:00 【Minaldo7】
subject :
In a m*n There is a gift in every space of the chessboard , Every gift has a certain value ( Value greater than 0). You can start from the top left corner of the chessboard to get the gifts in the grid , And move right or down one space at a time 、 Until you reach the bottom right corner of the chessboard . Given the value of a chessboard and its gifts , Please calculate the maximum value of gifts you can get ?
Example 1:
Input :
[
[1,3,1],
[1,5,1],
[4,2,1]
]
Output : 12
explain : route 1→3→5→2→1 Can get the most value gifts
Tips :
0 < grid.length <= 200
0 < grid[0].length <= 200
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
The problem solving process :
Dynamic programming
class Solution {
public int maxValue(int[][] grid) {
int m=grid.length,n=grid[0].length;
int dp[] = new int[n+1];
int max = grid[0][0];
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
dp[j] = Math.max(dp[j-1],dp[j]) + grid[i-1][j-1];
}
}
return dp[n];
}
}
Execution results :

版权声明
本文为[Minaldo7]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/111/202204210544479416.html
边栏推荐
- Pytorch preserves different forms of pre training models
- C# 知识
- Addition, deletion, modification and query of advanced MySQL data (DML)
- [leetcode refers to offer 27. Image of binary tree (simple)]
- Chrome 94 introduces the controversial idle detection API, which apple and Mozilla oppose
- 居家第二十三天的午饭
- 小米手机全球已舍弃“MI”品牌,全面改用“xiaomi”全称品牌
- Pyuninstaller package exe cannot find the source code when running, function error oserror: could not get source code
- MySQL advanced common functions
- matplotlib. Pyplot partition drawing
猜你喜欢

Addition, deletion, modification and query of advanced MySQL data (DML)

居家第二十三天的午饭
![[leetcode refers to offer 27. Image of binary tree (simple)]](/img/65/85e63a8b7916af058d78d72d775530.png)
[leetcode refers to offer 27. Image of binary tree (simple)]

What about laptop Caton? Teach you to reinstall the system with one click to "revive" the computer

Write table of MySQL Foundation (create table)

Arm architecture assembly instructions, registers and some problems

Deno 1.13.2 发布

GSI-ECM工程建设管理数字化平台

What if Jenkins forgot his password

浅谈数据库设计之三大范式
随机推荐
Realrange, reduce, repeat and einops in einops package layers. Rearrange and reduce in torch. Processing methods of high-dimensional data
IOT 设计与开发
LeetCode-279-完全平方数
wait、waitpid
[leetcode refers to offer 27. Image of binary tree (simple)]
The computer is out of power. How did I pass the terrible interview of Tencent cloud?
41. 缺失的第一个正数
Tensorflow1. X and 2 How does x read those parameters saved in CKPT
Gsi-ecm digital platform for engineering construction management
Common problems in deploying projects with laravel and composer for PHP
unity 功能扩展
UKFslam
Use 3080ti to run tensorflow GPU = 1 X version of the source code
学会打字后的思考
ROS learning notes - tutorial on the use of ROS
ros功能包内自定义消息引用失败
Pytorch selects the first k maximum (minimum) values and their indexes in the data
pikachuxss如何获取cookie靶场,返回首页总是失败
使用mbean 自动执行heap dump
Reference of custom message in ROS function pack failed