当前位置:网站首页>Maximum value of jz47 gifts (dynamic planning ideas)
Maximum value of jz47 gifts (dynamic planning ideas)
2022-07-24 06:25:00 【Happy and at ease】

The key of dynamic programming is , seek dp Equation of state , Compare the results with dp State binding , The solving problem is divided into several sub problems , So as to solve the result

For the whole process , Let's consider the special situation first , That is, gifts are only along the first 0 OK or the second 0 The column moves , So the gift value grid[i][j]+=grid[i][j-1] perhaps grid[i][j]+=grid[i-1][j], In other cases grid[i][j]+=max(grid[i][j-1],grid[i-1][j])
The code is as follows
int maxValue(vector<vector<int> >& grid) {
// write code here
int col=grid[0].size();
int row=grid.size();
if(row==0)
return 0;
for(int i=0;i<row;i++)
for(int j=0;j<col;j++){
if(j>0&&i>0)
grid[i][j]+=max(grid[i-1][j],grid[i][j-1]);
else if(j>0)
grid[i][j]+=grid[i][j-1];
else if(i>0)
grid[i][j]+=grid[i-1][j];
}
return grid[row-1][col-1];
}
};边栏推荐
猜你喜欢
![[218] what are the advantages and disadvantages of CS architecture and BS architecture and data on the server and client?](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[218] what are the advantages and disadvantages of CS architecture and BS architecture and data on the server and client?

【301】怪诞行为学-可预测的非理性

IA课总结(1)

IP课(OSPF)综合实验

利用内网穿透,实现公网访问内网

A batch of interview questions and answers_ 20180403 latest arrangement

Simple three-step fast intranet penetration

Leetcode剑指offer JZ9 双栈实现队列

leetcode剑指offer jz5 替换空格字符串
![Public access intranet IIS website server [no public IP required]](/img/e5/45d7c59ed30bbf901f793f25e229e2.png)
Public access intranet IIS website server [no public IP required]
随机推荐
leetcode剑指offer JZ73 翻转单词序列
Unity shader: realize diffuse reflection and specular reflection
ip作业(1)
EXCEL 生成mysql语句批量操作
Openpose2d transform 3D pose recognition
【测试工具】
IP作业(2)RIP
项目上复盘引导问题清单
MySQL从基础到入门到高可用
IP笔记(8)
Jenkins自动化无人值守运行(上/下)
剑指offer JZ10斐波那契数列
Simple three-step fast intranet penetration
公网访问内网IIS网站服务器【无需公网IP】
What is monotonic queue
IP笔记(6)
配置固定的远程桌面地址【内网穿透、无需公网IP】
UE4 reload system 2. Scene capture of reload system
Unity2d horizontal game jump real-time response
Flink production environment configuration recommendations