CODE1
CODE1
visited[x][y] = True
for i in range(4):
new_x, new_y = x + row[i], y + col[i]
if is_valid(grid, new_x, new_y, visited):
if i == 0:
current_path.append('U')
elif i == 1:
current_path.append('D')
elif i == 2:
current_path.append('L')
elif i == 3:
current_path.append('R')
dfs(grid, new_x, new_y, end_x, end_y, visited, current_path,
current_cost + grid[new_x][new_y], min_cost, best_path, all_paths)
current_path.pop()
visited[x][y] = False
grid = [
[1, 2, 1, 1],
[2, -1, 0, 1],
[3, 1, 1, 1],
[4, 1, 1, 1]
]
start_x, start_y = 0, 0
end_x, end_y = 3, 2
-----------------OUTPUT --------------
Total paths found: 26
Path 1: DDDRURUURDDDL
Path 2: DDDRURURDDL
Path 3: DDDRURD
Path 4: DDDRURRDL
Path 5: DDDRR
Path 6: DDRDR
Path 7: DDRRUURDDDL
Path 8: DDRRURDDL
Path 9: DDRRD
Path 10: DDRRRDL
Path 11: RRDDD
Path 12: RRDDLDR
Path 13: RRDDLLDRR
Path 14: RRDDRDL
Path 15: RRDRDDL
Path 16: RRDRDLD
Path 17: RRDRDLLDR
Path 18: RRDRDLLLDRR
Path 19: RRRDDDL
Path 20: RRRDDLD
Path 21: RRRDDLLDR
Path 22: RRRDDLLLDRR
Path 23: RRRDLDD
Path 24: RRRDLDLDR
Path 25: RRRDLDLLDRR
Path 26: RRRDLDRDL