forked from strang3-r/Leetcode75
-
Notifications
You must be signed in to change notification settings - Fork 0
/
floodfill.cpp
44 lines (38 loc) · 1007 Bytes
/
floodfill.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <vector>
using namespace std;
void printfloodfill(int[][] maze, int row, int col, string psf, bool visited[][])
{
//base case
if ((row < 0) || (col < 0) || row >= n || col >= m || maze[row][col] == 1 || visited[row][col] == true)
{
return;
}
if (row == size() && col ==)
{
cout << psf << endl;
return;
}
visited[row][col] = true;
printfloodfill(maze, row - 1, col, psf + "T", visited);
printfloodfill(maze, row, col - 1, psf + "L", visited);
printfloodfill(maze, row + 1, col, psf + "D", visited);
printfloodfill(maze, row, col + 1, psf + "R", visited);
visited[row][col] = false;
}
int main()
{
int n, m;
cin >> n >> m;
int arr[n][m];
vector<vector<int>> arr(n, vector<int>(m));
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cin >> arr[i][j];
}
}
bool visited[n][m];
printfloodfill(arr, 0, 0, "", visited);
}