Henu
개발냥발
Henu
전체 방문자
오늘
어제
  • 분류 전체보기 (411)
    • DevOps (52)
      • Kubernetes (19)
      • Docker (14)
      • AWS (3)
      • Nginx (4)
      • Linux (4)
      • ArgoCD (1)
      • CN (2)
      • NATS (0)
      • Git (5)
    • Back-End (30)
      • Django (18)
      • Spring (5)
      • JPA (1)
      • MSA (5)
    • CS (87)
      • SystemSoftware (20)
      • OS (25)
      • Computer Architecture (16)
      • Network (23)
      • Database (2)
    • Lang (21)
      • Java (9)
      • Python (4)
      • C# (8)
    • Life (12)
    • 블록체인 (2)
    • Algorithm (204)
      • BOJ (160)
      • 프로그래머스 (19)
      • LeetCode (4)
      • SWEA (1)
      • 알고리즘 문제 해결 전략 (8)
      • DS, algorithms (7)
      • Checkio (5)
    • IT (2)

블로그 메뉴

  • GitHub
  • 글쓰기
  • 관리자

공지사항

  • Free!

인기 글

태그

  • Kubernetes
  • django
  • boj
  • DFS
  • BFS
  • 백트래킹
  • docker
  • Network
  • 프로그래머스
  • 다이나믹 프로그래밍

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Henu

개발냥발

[백준 1890] 점프 C++
Algorithm/BOJ

[백준 1890] 점프 C++

2021. 7. 21. 02:41
 

1890번: 점프

첫째 줄에 게임 판의 크기 N (4 ≤ N ≤ 100)이 주어진다. 그 다음 N개 줄에는 각 칸에 적혀져 있는 수가 N개씩 주어진다. 칸에 적혀있는 수는 0보다 크거나 같고, 9보다 작거나 같은 정수이며, 가장

www.acmicpc.net

다이나믹 프로그래밍


dfs top-down방식으로 2차원 cache를 적용한 풀이.

 

Cache[r][c] = r, c에서 점프해서 N-1, N-1에 도달할 수 있는 경우의 수.

 

long long 주의.

 

N-1, N-1에 도달하면 1을 리턴.

Map의 원소가 0이면 0을 바로 리턴.

 

 

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
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>
#define fasti ios_base::sync_with_stdio(false); cin.tie(0);
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 1e9+7
#define pii pair<int, int>
 
typedef long long ll;
// typedef pair<int, int> pii;
 
using namespace std;
 
int N;
int Map[101][101];
ll Cache[101][101];
 
void input(){
    cin >> N;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            cin >> Map[i][j];
        }
    }
    memset(Cache, -1, sizeof(Cache));
}
 
ll dfs(pii now){
    if(now.first == N-1 && now.second == N-1){
        return 1;
    }
    if(!Map[now.first][now.second]){
        return 0;
    }
    
    ll &ret = Cache[now.first][now.second];
    if(ret != -1) return ret;
    
    ret = 0;
    int jump = Map[now.first][now.second];
    
    pii npii1 = {now.first + jump, now.second};
    pii npii2 = {now.first, now.second + jump};
    
    return ret = dfs(npii1) + dfs(npii2);
}
 
void solve(){
    dfs({0, 0});
    cout << Cache[0][0];
}
 
int main(){
    input();
    solve();
    
    return 0;
}
 
Colored by Color Scripter
cs

 

'Algorithm > BOJ' 카테고리의 다른 글

[백준 20165] 인내의 도미노 장인 호석 C++  (0) 2021.07.22
[백준 16681] 등산 C++  (0) 2021.07.21
[백준 2573] 빙산 C++  (0) 2021.07.21
[백준 3977] 축구 전술 C++  (0) 2021.07.21
[백준 1504] 특정한 최단경로 C++  (0) 2021.07.16
    'Algorithm/BOJ' 카테고리의 다른 글
    • [백준 20165] 인내의 도미노 장인 호석 C++
    • [백준 16681] 등산 C++
    • [백준 2573] 빙산 C++
    • [백준 3977] 축구 전술 C++

    티스토리툴바