Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 우선순위 큐
- 백준
- c++
- 그리디 알고리즘
- BFS
- 투 포인터
- 다익스트라
- 재귀
- Unreal Engine 5
- XR Interaction Toolkit
- 다이나믹 프로그래밍
- 시뮬레이션
- 브루트포스
- 유니티
- 문자열
- 백트래킹
- Team Fortress 2
- DFS
- 수학
- 자료구조
- VR
- 정렬
- 알고리즘
- ue5
- 그래프
- 트리
- 누적 합
- 스택
- 구현
- 유니온 파인드
Archives
- Today
- Total
1일1알
백준 1890번 점프 C++ 본문
Dfs+DP
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
#include <bitset>
using namespace std;
using int64 = long long;
int n;
vector<vector<int64>> board;
vector<vector<int64>> cache;
int64 Jump(int row, int col) {
int64& val = cache[row][col];
if (val != -1) return val;
if (row == n - 1 && col == n - 1) return val = 1;
val = 0;
if (board[row][col] == 0) return val;
int nextRow = row + board[row][col];
int nextCol = col + board[row][col];
if (nextRow < n)
val += Jump(nextRow, col);
if (nextCol < n)
val += Jump(row, nextCol);
return val;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
board = vector<vector<int64>>(n, vector<int64>(n));
cache = vector<vector<int64>>(n, vector<int64>(n, -1));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> board[i][j];
}
}
cout << Jump(0, 0);
}
'알고리즘' 카테고리의 다른 글
백준 14442번 벽 부수고 이동하기 2 C++ (1) | 2022.09.21 |
---|---|
백준 17396번 백도어 C++ (0) | 2022.09.20 |
백준 17135번 캐슬 디펜스 C++ (0) | 2022.09.18 |
백준 25307번 시루의 백화점 구경 C++ (0) | 2022.09.17 |
백준 19238번 스타트 택시 C++ (0) | 2022.09.16 |