Triangle DP求最大和
来源:互联网 发布:nginx伪静态规则写法 编辑:程序博客网 时间:2024/06/06 14:00
Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.
For example, given the following triangle
[ [2], [3,4], [6,5,7], [4,1,8,3]]
The minimum path sum from top to bottom is 11
(i.e., 2 + 3 + 5 + 1 = 11).
Note:
Bonus point if you are able to do this using only O(n) extra space, where n is the total number of rows in the triangle.
class Solution {public: int minimumTotal(vector<vector<int> > &triangle) { int n=triangle.size(); vector<int> dp(n); for(int i=0;i<n;i++) dp[i]=triangle[n-1][i]; for(int i=n-2;i>=0;i--) { for(int j=0;j<=i;j++) { dp[j]=triangle[i][j]+min(dp[j],dp[j+1]); } } return dp[0]; }};
0 0
- Triangle DP求最大和
- dp求最大和序列
- 求连续段最大和(dp)
- 求子数组的最大和【DP】
- DP 求子数组的最大和
- 求最大连续和——dp
- 求最大子列和 dp
- NYOJ104 最大和(dp+求最大子矩阵)
- HDU--1864:最大报销额 DP求最大和(最大和有上限)
- POJ 1163 The Triangle (简单 DP 数字的最大路线和)
- 求最大连续子段和 的 dp算法
- 【算法总结-DP】求子数组的最大和
- hdu1081求最大子矩阵的和,DP
- 求最大连续子段和 的 dp算法
- DP之简单的求最大字段和问题
- 【算法总结-DP】求子数组的最大和
- dp问题 求连续序列的最大和
- HDOJ 1003 经典DP--求最大字串和
- 递归算法及经典递归例子代码实现
- baseAdapt getView 重复执行很对遍原因
- 黑马程序员—经典题目:兔子问题
- 欢迎使用CSDN-markdown编辑器
- SqlServer bug:sp_replqueuemonitor 在SqlServer 2008(RTM) 执行无结果
- Triangle DP求最大和
- python 统计pvuv 二
- android判断手机SIM状态
- Spark Core源码分析: RDD基础
- EditText 判断有没有获得焦点
- HttpClientUtil访问方式
- 【Oracle数据库技术支持】RAC性能分析 - gc buffer busy acquire 等待事件
- Pascal's Triangle
- 基于MATLAB中fft2函数的二维图像数据的频谱生成代码