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.

利用动态规划的知识求解。从左上开始,遍历到右下。考虑边界情况。

代码如下:

public class Solution {
public int MinPathSum(int[,] grid) { int row=grid.GetLength();
int col=grid.GetLength(); for(int i=;i<row;i++)
{
for(int j=;j<col;j++)
{
if(i==&&j!=)
{
grid[i,j]=grid[i,j]+grid[i,j-];
}
else if(i!=&&j==)
{
grid[i,j]=grid[i,j]+grid[i-,j];
}
else if(i==&&j==)
{
grid[i,j]=grid[i,j];
}
else
{
grid[i,j]= grid[i,j]+Math.Min(grid[i-,j],grid[i,j-]);
}
}
} return grid[row-,col-];
}
}

C#解leetcode 64. Minimum Path Sum的更多相关文章

  1. [LeetCode] 64. Minimum Path Sum 最小路径和

    Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...

  2. LeetCode 64. Minimum Path Sum(最小和的路径)

    Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...

  3. LeetCode 64 Minimum Path Sum

    Problem: Given a m x n grid filled with non-negative numbers, find a path from top left to bottom ri ...

  4. [leetcode]64. Minimum Path Sum最小路径和

    Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...

  5. leetCode 64.Minimum Path Sum (最短路) 解题思路和方法

    Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...

  6. [leetcode] 64. Minimum Path Sum (medium)

    原题 简单动态规划 重点是:grid[i][j] += min(grid[i][j - 1], grid[i - 1][j]); class Solution { public: int minPat ...

  7. leecode 每日解题思路 64 Minimum Path Sum

    题目描述: 题目链接:64 Minimum Path Sum 问题是要求在一个全为正整数的 m X n 的矩阵中, 取一条从左上为起点, 走到右下为重点的路径, (前进方向只能向左或者向右),求一条所 ...

  8. 刷题64. Minimum Path Sum

    一.题目说明 题目64. Minimum Path Sum,给一个m*n矩阵,每个元素的值非负,计算从左上角到右下角的最小路径和.难度是Medium! 二.我的解答 乍一看,这个是计算最短路径的,迪杰 ...

  9. 【LeetCode】64. Minimum Path Sum

    Minimum Path Sum Given a m x n grid filled with non-negative numbers, find a path from top left to b ...

随机推荐

  1. iOS 宏定义_16进制色值转化为RGB返回UIColor类型对象

    // 十六进制颜色 #define COLOR_WITH_HEX(hexValue) [UIColor colorWithRed:((float)((hexValue & 0xFF0000) ...

  2. 下一代hadoop

    1,hadoop 2.0 产生背景2,hadoop 2.0 基本构成3,HDFS 2.04 YARN5 MapReduce On YARN6 Hadoop 2.0初体验7 总结 1,hadoop 2. ...

  3. eclipse配置hadoop的错误

    配置好eclipse,在执行run on hadoop的时候,提示11/03/29 16:47:59 WARN conf.Configuration: DEPRECATED: hadoop-site. ...

  4. LINUX6.3下RHCS的安装文档

    LINUX6.3下RHCS的安装及集群的配置文档 环境: 目前要给华为E6000系列的两个刀片安装RHCS,每一块刀片有两个业务网口和一个管理网口,但是看不见不物理网卡,而是连接到刀片自身携带的一个交 ...

  5. BZOJ2134: 单选错位

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2134 题解:因为每个答案之间是互不影响的,所以我们可以挨个计算. 假设当前在做 i 题目,如果 ...

  6. 跨浏览器读取XML

    这里跨浏览器,但是只能读取字符串XML文档,可以通过Ajax方式load一个XML文档,将文件XML转变为字符串 // 跨浏览器返回XML DOM对象 function getXMLDOM(xmlSt ...

  7. ubuntu制作usb启动盘

    准备: u盘 iso镜像文件--ubuntu-12.04.2-desktop-amd64.iso 烧盘软件--unetbootin-linux-583 步骤: 格式化u盘 查看u盘信息 #mount/ ...

  8. AQL Subset Compiler:手把手教你如何写一个完整的编译器

    项目地址:https://github.com/laiy/Awesome-Complier. 转载请注明出处. 前言 这是学校里编译原理课程的大作业,此Project十分适合编译原理的学习,让基本不听 ...

  9. The Doors - POJ 1556 (线段相交)

    题目大意:有一个房间(左上角(0,10),右下角(10,0)),然后房间里有N面墙,每面墙上都有两个门,求出来从初始点(0,5),到达终点(10,5)的最短距离.   分析:很明显根据两点之间直线最短 ...

  10. 在浏览器中简单输入一个网址,解密其后发生的一切(http请求的详细过程)

    在浏览器中简单输入一个网址,解密其后发生的一切(http请求的详细过程) 原文链接:http://www.360doc.com/content/14/1117/10/16948208_42571794 ...