-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path파이프 옮기기 1.cc
41 lines (39 loc) · 1.16 KB
/
파이프 옮기기 1.cc
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
#include <bits/stdc++.h>
using namespace std;
int n, a[24][24], dp[24][24][3];
bool check(int y, int x, int d){
if(d==0 || d==2){
if(!a[y][x]) return true;
} else if(d==1){
if(a[y][x]==0 && a[y-1][x]==0 && a[y][x-1]==0) return true;
}
return false;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
cin >> a[i][j];
}
}
dp[1][2][0]=1;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
if(check(i,j+1,0)) dp[i][j+1][0] += dp[i][j][0];
if(check(i+1,j+1,1)) dp[i+1][j+1][1] += dp[i][j][0];
if(check(i+1,j,2)) dp[i+1][j][2] += dp[i][j][2];
if(check(i+1,j+1,1)) dp[i+1][j+1][1] += dp[i][j][2];
if(check(i,j+1,0)) dp[i][j+1][0] += dp[i][j][1];
if(check(i+1,j,2)) dp[i+1][j][2] += dp[i][j][1];
if(check(i+1,j+1,1)) dp[i+1][j+1][1] += dp[i][j][1];
}
}
int ret = dp[n][n][0];
ret += dp[n][n][1];
ret += dp[n][n][2];
cout << ret << "\n";
return 0;
}