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 grid.
for example,
there is one obstacle in the middle of a 3x3 grid as illustrated below.
the total number of unique paths is 2.
寻求最短路径,从左上走到右下,保证每次只能往左走或往下走(不可以斜着走)。其中数字1是障碍,表示“此路不通”,求总共的路线数。
第一种二维数组
用一个二维数组来表示前者的路径
核心就是这个,如果不等于1,我们就找到前者的路径相加。
第二种一维数组
其实一维数组足以表示前者的路径,因为一维数组左边是你更新过的,右边是没更新,没更新的相当于上一排,也就是上一排的来路加上左边的来路之和就是现在的来路。(解释好混乱,但我是这样想就理解了)