Skip to content

Commit bb31958

Browse files
committed
2 parents 3f3af4e + 43613ee commit bb31958

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <string>
2+
#include <vector>
3+
int cache[101][101];
4+
using namespace std;
5+
int M, N;
6+
int map[101][101];
7+
vector<vector<int>> v;
8+
void init(int m, int n, vector<vector<int>> puddles) {
9+
M = m;
10+
N = n;
11+
for (int i = 0; i < puddles.size(); i++) {
12+
map[puddles[i][0]][puddles[i][1]] = 1;
13+
}
14+
for (int i = 1; i <= m; i++) {
15+
for (int j = 1; j <= n; j++) {
16+
cache[i][j] = -1;
17+
}
18+
}
19+
}
20+
int goSchool(int y, int x) {
21+
if (y > M || x > N) return 0;
22+
if (y == M && x == N) return 1;
23+
if (map[y][x] == 1) return 0;
24+
if (cache[y][x] != -1) return cache[y][x];
25+
return cache[y][x] = (goSchool(y + 1, x) + goSchool(y, x + 1)) % 1000000007;
26+
}
27+
int solution(int m, int n, vector<vector<int>> puddles) {
28+
init(m, n, puddles);
29+
30+
return goSchool(1, 1);
31+
}

0 commit comments

Comments
 (0)