-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdem_so_duong_di_trong_me_cung.cpp
More file actions
80 lines (79 loc) · 1.61 KB
/
dem_so_duong_di_trong_me_cung.cpp
File metadata and controls
80 lines (79 loc) · 1.61 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
char a[1005][1005];
ll dp[1005][1005];
int dx[2] = {0, 1};
int dy[2] = {1, 0};
int n;
void bfs()
{
queue<pair<int, int>> q;
ll dem = 0;
q.push({1, 1});
if(a[1][1] == '*' || a[n][n] == '*')
{
cout << 0 << endl;
}
while (!q.empty())
{
pair<int, int> x = q.front();
q.pop();
if (x.first == n && x.second == n)
{
dem++;
dem %= MOD;
}
for (int k = 0; k < 2; k++)
{
int i1 = x.first + dx[k];
int j1 = x.second + dy[k];
if (i1 >= 1 && i1 <= n && j1 >= 1 && j1 <= n && a[i1][j1] == '.')
{
q.push({i1, j1});
}
}
}
cout << dem << endl;
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
cin >> a[i][j];
}
}
// tinh toan
if(a[1][1] == '*' || a[n][n] == '*')
{
cout << 0 << endl;
}
else
{
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
if(i == 1 && j == 1)
{
dp[i][j] = 1;
}
if(a[i][j] == '*')
{
dp[i][j] = 0;
}
else
{
dp[i][j] += (dp[i-1][j] + dp[i][j-1]);
dp[i][j] %= MOD;
}
}
}
cout << dp[n][n] << endl;
}
// bfs();
}