-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17069.cpp
More file actions
53 lines (46 loc) · 1.21 KB
/
17069.cpp
File metadata and controls
53 lines (46 loc) · 1.21 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
// 17069. 파이프 옮기기 2
// 2021.06.07
// 다이나믹 프로그래밍
#include<iostream>
using namespace std;
int map[33][33];
long long d[33][33][3];
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cin >> map[i][j];
}
}
// d[i][j][k] : i,j에서 k방향인 경우의 수
d[0][1][0] = 1;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
// 가로 이동
if (map[i][j + 1] == 0)
{
d[i][j + 1][0] += d[i][j][0] + d[i][j][2];
}
// 세로 이동
if (map[i + 1][j] == 0)
{
d[i + 1][j][1] += d[i][j][1] + d[i][j][2];
}
// 대각선 이동
// 오른쪽 칸과 아래칸도 0이어야 이동할 수 있다.
if (map[i + 1][j] == 0 && map[i][j + 1] == 0 && map[i + 1][j + 1] == 0)
{
d[i + 1][j + 1][2] += d[i][j][0] + d[i][j][1] + d[i][j][2];
}
}
}
long long ans = d[n - 1][n - 1][0] + d[n - 1][n - 1][1] + d[n - 1][n - 1][2];
cout << ans << endl;
return 0;
}