forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path(CSES)Grid Paths.cpp
59 lines (57 loc) · 1.3 KB
/
(CSES)Grid Paths.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
int32_t main()
{
int n;
cin >> n;
char a[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> a[i][j];
int dp[n][n];
bool f = 0, f1 = 0;
if (a[n - 1][n - 1] == '*')
{
cout << 0;
return 0;
}
memset(dp, 0, sizeof dp);
for (int i = n - 1; i >= 0; i--)
{
for (int j = n - 1; j >= 0; j--)
{
if (i == n - 1)
{
if (a[i][j] == '*')
{
dp[i][j] = 0;
f = 1;
}
else if (!f)
dp[i][j] = 1;
}
else if (j == n - 1)
{
if (a[i][j] == '*')
{
dp[i][j] = 0;
f1 = 1;
}
else if (!f1)
dp[i][j] = 1;
}
else
{
if (a[i][j] == '*')
dp[i][j] = 0;
else
dp[i][j] = (dp[i + 1][j] + dp[i][j + 1]) % mod;
}
}
}
cout << dp[0][0] % mod;
;
return 0;
}