-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGridPaths.cpp
More file actions
39 lines (34 loc) · 845 Bytes
/
GridPaths.cpp
File metadata and controls
39 lines (34 loc) · 845 Bytes
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
//Grid Paths - https://cses.fi/problemset/task/1638
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
void solve() {
int n;
cin >> n;
vector<string> grid(n);
for (int i = 0; i < n; i++) {
cin >> grid[i];
}
vector<vector<ll>> dp = vector<vector<ll>>(n + 1, vector<ll>(n + 1, 0));
dp[1][1] = (grid[0][0] != '*');
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (grid[i][j] == '*') continue;
dp[i + 1][j + 1] += dp[i][j + 1] + dp[i + 1][j];
dp[i + 1][j + 1] %= MOD;
}
}
cout << dp[n][n] % MOD << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}