-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path576.cpp
More file actions
44 lines (40 loc) · 1.07 KB
/
Copy path576.cpp
File metadata and controls
44 lines (40 loc) · 1.07 KB
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 "common.h"
using namespace std;
class Solution {
public:
vector<vector<uint64_t>> dp;
const int mod = 1000000000 + 7;
int findPaths(int m, int n, int maxMove, int startRow, int startColumn) {
uint64_t rst = 0;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
dp.resize(m, vector<uint64_t>(n, 0));
dp[startRow][startColumn] = 1;
for (size_t count = 0; count < maxMove; count++) {
vector<vector<uint64_t>> temp(m, vector<uint64_t>(n));
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (dp[i][j] == 0) {
continue;
}
for (int dir = 0; dir < 4; dir++) {
int x = i + dx[dir];
int y = j + dy[dir];
if (x < 0 || x >= m || y < 0 || y >= n) {
rst = (rst + dp[i][j]) % mod;
} else {
temp[x][y] = (temp[x][y] + dp[i][j]) % mod;
}
}
}
}
dp = temp;
}
return rst;
}
};
int main() {
Solution s;
cout << s.findPaths(1, 2, 50, 0, 0) << endl;
return 0;
}