LeetCode_Minimun Path Sum
来源:互联网 发布:传奇账号数据库 编辑:程序博客网 时间:2024/05/23 18:40
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.
Note: You can only move either down or right at any point in time.
典型的动态规划小题!
#include <iostream>#include <vector>using namespace std;class Solution {public: int minPathSum(vector<vector<int> > &grid) { int rowNo = grid.size(); if(rowNo == 0){return 0;} int colNo = grid[0].size(); if (colNo == 0){ return 0; } std::vector <vector<int>> dp (rowNo,std::vector<int> (colNo,0)); dp[0][0]=grid[0][0]; for(int i=1;i<rowNo;i++){ dp[i][0]=dp[i-1][0]+grid[i][0]; } for(int j=1;j<colNo;j++){ dp[0][j]=dp[0][j-1]+grid[0][j]; } //start dp for(int i=1;i<rowNo;i++){ for(int j=1;j<colNo;j++){ if(dp[i-1][j]>dp[i][j-1]){ dp[i][j]=dp[i][j-1]+grid[i][j]; } else{ dp[i][j]=dp[i-1][j]+grid[i][j]; } } } return dp[rowNo-1][colNo-1]; }};
0 0
- LeetCode_Minimun Path Sum
- Path Sum && Path Sum ||
- Path Sum
- Path Sum
- Path Sum
- Path Sum
- Path Sum
- Path Sum
- Path Sum
- Path Sum
- Path Sum
- Path Sum
- Path Sum
- Path Sum
- Path Sum
- Path Sum
- Path Sum
- Path Sum
- Android OpenGL ES 开发教程(8):基本几何图形定义
- COCOS2DX中关于labelTTF控件获取不到触摸点的解决办法
- POJ 2288 Islands and Bridges(状态压缩)
- HDU 1398 Square Coins
- 设计模式-目录
- LeetCode_Minimun Path Sum
- codeforces #260 DIV 2 C题Boredom(DP)
- HDU-1754-I Hate It
- CF Round #260 (Div 2)
- ios 常见错误
- ios libxml/tree.h file not found解决办法
- HttpClient入门
- poj 1845(等比数列前n项和及快速幂)
- strace解决ssh登陆缓慢