def print_grid(m, n): if m == 1 and n == 1: print("\tS/D") else: for i in range(m): for j in range(n): if i == 0 and j == 0: print("\tS", end=" ") elif i == m-1 and j == n-1: print("D", end=" ") elif j == 0: print("\tx", end=" ") # You can change "X" to any character you want else: print("x", end=" ") print() def unique_paths(m, n): # Create a 2D grid filled with 1s, representing paths to each cell grid = [[1] * n for _ in range(m)] # Iterate through each row and column (excluding the first) in the grid for row in range(1, m): for col in range(1, n): # Calculate the number of unique paths to the current cell # by summing up paths from the cell above and the cell to the left grid[row][col] = grid[row - 1][col] + grid[row][col - 1] # Return the number of unique paths to the last cell (bottom-right corner) return grid[m - 1][n - 1] # Driver code def main(): input = ( [1, 1], [2, 3], [4, 4], [2, 5], [10, 10], [1, 30] ) for i in range(len(input)): print(i + 1, ".\tm = ", input[i][0], ", n = ", input[i][1], sep="") print("\n\tThe grid: ") print_grid(input[i][0], input[i][1]) ans = unique_paths(input[i][0], input[i][1]) print("\n\tTotal unique paths: ", ans) print("-"*100) if __name__ == '__main__': main()