-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path576.cpp
More file actions
18 lines (18 loc) · 840 Bytes
/
Copy path576.cpp
File metadata and controls
18 lines (18 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Solution {
public:
int findPaths(int m, int n, int N, int x, int y) {
vector<vector<vector<unsigned int>>> dp(m, vector<vector<unsigned int>>(n, vector<unsigned int>(N + 1, 0)));
for (int k = 1; k <= N; ++k) {
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
unsigned int up = (i == 0 ? 1 : dp[i - 1][j][k - 1]) % 1000000007;
unsigned int down = (i == m - 1 ? 1 : dp[i + 1][j][k - 1]) % 1000000007;
unsigned int left = (j == 0 ? 1 : dp[i][j - 1][k - 1]) % 1000000007;
unsigned int right = (j == n - 1 ? 1 : dp[i][j + 1][k - 1]) % 1000000007;
dp[i][j][k] = (up + down + left + right) % 1000000007;
}
}
}
return dp[x][y][N];
}
};