题目:leetcode
Dungeon Game
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. ...
分类:
其他好文 时间:
2015-04-06 08:51:43
阅读次数:
150
这道题采用动态规划的思想。参考了别人的做法。class Solution{public: vector> result; vector> partition(string s) { int len = s.length(); vector soloresult; if(s.leng...
分类:
其他好文 时间:
2015-04-05 18:47:49
阅读次数:
141
我以此题为例,详细分析01背包问题,希望该题能够为初学者对01背包问题的理解有所帮助,有什么问题可以向我提供,一同进步^_^饭卡Time Limit: 5000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total S...
分类:
其他好文 时间:
2015-04-05 18:43:05
阅读次数:
188
Follow up for "Unique Paths":
Now consider if some obstacles are added to the grids. How many unique paths would there be?
An obstacle and empty space is marked as 1 and 0 respectively
in the ...
分类:
其他好文 时间:
2015-04-05 09:14:38
阅读次数:
113
对于动态规划,每个刚接触的人都需要一段时间来理解,特别是第一次接触的时候总是想不通为什么这种方法可行,这篇文章就是为了帮助大家理解动态规划,并通过讲解基本的01背包问题来引导读者如何去思考动态规划。本文力求通俗易懂,无异性,不让读者感到迷惑,引导读者去思考,所以如果你在阅读中发现有不通顺的地方,让....
分类:
其他好文 时间:
2015-04-05 00:56:00
阅读次数:
202
Floyd算法
Floyd算法又称为插点法,是一种用于寻找给定的加权图中多源点之间最短路径的算法。该算法名称以创始人之一、1978年图灵奖获得者、斯坦福大学计算机科学系教授罗伯特·弗洛伊德命名。
注意:由下面的练习可以看出,其实很多题目不是直接问你floyd怎么求最短路径,而是要你利用floyd的动态规划思想解决类似floyd的问题。
Floy...
分类:
编程语言 时间:
2015-04-04 19:46:50
阅读次数:
207
应该是非常简单的动态规划了,要随时的记录每个点的状态,这样递归的时候直接用就可以了,不需要再次寻找,大大减少时耗。重点是状态转移方程dp[x][y]=max(dp[x-1][y], dp[x+1][y], dp[x][y-1], dp[x][y+1])+1当前的最长长度,是四个方向最长长度加1D -...
分类:
其他好文 时间:
2015-04-04 16:29:47
阅读次数:
165
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
The robot can only move either down or right at any point in time. The robot is trying to reach the ...
分类:
其他好文 时间:
2015-04-04 13:47:15
阅读次数:
135
class Solution {
public:
int climbStairs(int n) {
vector table;
table.push_back(0);
table.push_back(1);
table.push_back(2);
if(n<=2)
return...
分类:
其他好文 时间:
2015-04-03 22:34:50
阅读次数:
184
思路:代码:class Solution {public: int rob(vector &num) { if(num.empty()) return 0; int size=num.size(); if(size==1) return num[0];...
分类:
其他好文 时间:
2015-04-03 12:47:12
阅读次数:
112