728x90
반응형
https://algospot.com/judge/problem/read/JUMPGAME
algospot.com :: JUMPGAME
외발 뛰기 문제 정보 문제 땅따먹기를 하다 질린 재하와 영훈이는 땅따먹기의 변종인 새로운 게임을 하기로 했습니다. 이 게임은 그림과 같이 n*n 크기의 격자에 각 1부터 9 사이의 정수를 쓴 상
algospot.com
메모제이션 기법을 통해서만 해결 가능한 문제
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#define MAX_SIZE 101
#define swap(type,x,y) do{type t=x; x=y;y=t;} while(0)
using namespace std;
int N;
int adj[MAX_SIZE][MAX_SIZE];
int graph[MAX_SIZE][MAX_SIZE];
int isPossible(int y, int x) {
if (y >= N || x >= N) return 0;
if (y == N - 1 && x == N - 1) return 1;
if (adj[y][x] != -1) return adj[y][x];
int jump = graph[y][x];
return adj[y][x] = (isPossible(y + jump, x) || isPossible(y, x + jump));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int test_case;
cin >> test_case;
while (test_case--) {
cin >> N;
memset(adj, -1, sizeof(adj));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cin >> graph[i][j];
}
}
if (isPossible(0,0)) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
728x90
반응형
'BOJ > DP' 카테고리의 다른 글
[C/C++] 백준 - 11057번 : 오르막 수 (0) | 2021.07.18 |
---|---|
[C/C++] 백준 - 11052번 : 카드 구매하기 (0) | 2021.07.15 |
[C/C++] 백준 - 11054번 : 가장 긴 바이토닉 부분 수열 (0) | 2021.07.11 |
[C/C++] 백준 - 2631번 : 줄세우기 (0) | 2021.07.11 |
[C/C++] 백준 - 12865번 : 평범한 배낭 (0) | 2021.07.10 |