由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 请教一道google面试题
相关主题
请教CareerCup中的ROBOT MATRIX PATH那道题关于index的问题
刚弄完Amazon online test, 求bless面试题
matrix question一道面试题,求解
某公司面试题,怎么解?求解一道面试题 snake sequence
一道面试题:matrix找第k大LinkedIn面试题请教
面试题:transpose a matrix in placeG家面试题: Longest Increasing Sequence 2D matrix
一道热门的 Google 面试题问一道G家面试题
请问一道google面试题★★求助:C++的面试一般会多难?★★
相关话题的讨论汇总
话题: int话题: matrix话题: start话题: end话题: path
进入JobHunting版参与讨论
1 (共1页)
c******t
发帖数: 1500
1
就是那道经典的
count paths in a matrix with obsticles
如果仅仅是count paths in a matrix,那么很简单的DP就解决了。下面是我写的C++代
码,在VS2008下调试通过:
int path(int start_x, int start_y, int end_x, int end_y)
{
if(start_x == end_x || start_y == end_y)
{
return 1;
}
return path(start_x + 1, start_y, end_x, end_y) + path(start_x, start_y
+ 1, end_x, end_y);
}
可是如果矩阵里面有障碍的话,我就不知道该怎么解决了
还请版里的各位达人赐教,多谢了!
g***s
发帖数: 3811
2
your codes are not DP. O(2^n)
you need store the visited nodes.
d**e
发帖数: 6098
3
please refer here
http://www.ihas1337code.com/2010/11/unique-paths.html
it should be similar. but you have to define what value in the cell stands
for obstacle and then add the checking. assume that all cells are non-
negative and 0 is obsacle.
int path(int [][] matrix, int m, int n){
matrix[m-1][n-1] = 1;
for(int r = m - 1; r >= 0; r--){
for(int c = n - 1; c >= 0; c--){
if(r == m - 1 && c == n - 1)
continue;
if(matrix[r][c] != 0)
matrix[r][c] = matrix[r+1][c] + matrix[r][c+1];
}
}
return matrix[0][0];
}

【在 c******t 的大作中提到】
: 就是那道经典的
: count paths in a matrix with obsticles
: 如果仅仅是count paths in a matrix,那么很简单的DP就解决了。下面是我写的C++代
: 码,在VS2008下调试通过:
: int path(int start_x, int start_y, int end_x, int end_y)
: {
: if(start_x == end_x || start_y == end_y)
: {
: return 1;
: }

1 (共1页)
进入JobHunting版参与讨论
相关主题
★★求助:C++的面试一般会多难?★★一道面试题:matrix找第k大
Unix/Linux下的C++ coding 跟Windows下到底有多大不同?面试题:transpose a matrix in place
调试成功的next_permutation代码一道热门的 Google 面试题
请教,划分回文的最小cut次数,调试不出来请问一道google面试题
请教CareerCup中的ROBOT MATRIX PATH那道题关于index的问题
刚弄完Amazon online test, 求bless面试题
matrix question一道面试题,求解
某公司面试题,怎么解?求解一道面试题 snake sequence
相关话题的讨论汇总
话题: int话题: matrix话题: start话题: end话题: path