본문 바로가기

Coding/백준

1890번 점프

 기본적인 DP + DFS 문제.

 

 아래, 오른쪽 두개의 방향만 생각해서 풀면 된다(계속 네 방향을 고려해서 문제를 푸는데 오래 걸렸다).

 

 

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
#include <iostream>
#define MAX 101
 
using namespace std;
 
int N;
int map[MAX][MAX];
int xx[2]={1,0};
int yy[2]={0,1};
long cnt[MAX][MAX];
 
void solved(int x, int y){
    
    if(cnt[x][y]!=-1){
        return;
    }
    
    if(x==N-1 && y==N-1){
        cnt[x][y]=1;
        return;
    }
    
    cnt[x][y]=0;
    
    for(int i=0;i<2;i++){
        int nx=map[x][y]*xx[i]+x;
        int ny=map[x][y]*yy[i]+y;
        
        if(nx<0 || ny<0 || nx>=|| ny>=N) continue;
        solved(nx,ny);
        cnt[x][y]+=cnt[nx][ny];
    }
}
 
int main(){
    cin >> N;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin >> map[i][j];
            cnt[i][j]=-1;
        }
    }
    
    solved(0,0);
    
    cout << cnt[0][0<< endl;
}
 
cs

'Coding > 백준' 카테고리의 다른 글

2210번 숫자판 점프  (0) 2020.03.19
14888번 연산자 끼워넣기  (0) 2020.03.17
1965번 상자넣기  (0) 2020.03.16
2225번 합분해  (0) 2020.03.14
1517번 버블소트  (0) 2020.03.13