-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrid_Paths.cpp
66 lines (58 loc) · 1.16 KB
/
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
60
61
62
63
64
65
66
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int max_size = 1010;
int dp[max_size][max_size];
int obstacles[max_size][max_size];
int main()
{
int n;
cin >> n;
int i, j;
string s;
for(i = 1; i <= n; i++)
{
cin >> s;
for(j = 1; j <= n; j++)
{
if(s[j - 1] == '*')
{
obstacles[i][j] = 1;
}
else
{
obstacles[i][j] = 0;
}
}
}
for(i = 1; i <= n; i++)
{
for(j = 1; j <= n; j++)
{
if(i == 1 and j == 1)
{
if(obstacles[i][j])
{
dp[i][j] = 0;
}
else
{
dp[i][j] = 1;
}
}
else
{
if(obstacles[i][j])
{
dp[i][j] = 0;
}
else
{
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
}
}
}
}
cout << dp[n][n] << endl;
return 0;
}