Algorithm/알고스팟
algospot - jumpgame
jhg0406
2020. 2. 2. 14:36
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
|
//algospot - jumpgame
#include <bits/stdc++.h>
using namespace std;
int N;
vector<vector<int>> arr;
vector<vector<int>> mem;
void init()
{
cin >> N;
arr = vector<vector<int>>(N, vector<int>(N));
mem = vector<vector<int>>(N, vector<int>(N, -1));
for(int i = 0; i<N; ++i)
for(int j = 0; j<N; ++j)
cin >> arr[i][j];
}
int dp(int x, int y)
{
if(x == N-1 && y == N-1)
return 1;
int& ret = mem[x][y];
if(ret != -1)
return ret;
ret = 0;
int num = arr[x][y];
if(x + num < N)
ret += dp(x+num, y);
if(y + num < N)
ret += dp(x, y+num);
return ret;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int C; cin >> C;
for(int tn = 0; tn < C; ++tn)
{
init();
int flag = dp(0, 0);
if(flag)
cout << "YES" << "\n";
else
cout << "NO" << "\n";
}
}
|
cs |
https://www.algospot.com/judge/problem/read/JUMPGAME
algospot.com :: JUMPGAME
외발 뛰기 문제 정보 문제 땅따먹기를 하다 질린 재하와 영훈이는 땅따먹기의 변종인 새로운 게임을 하기로 했습니다. 이 게임은 그림과 같이 n*n 크기의 격자에 각 1부터 9 사이의 정수를 쓴 상태로 시작합니다. 각 차례인 사람은 맨 왼쪽 윗 칸에서 시작해 외발로 뛰어서 오른쪽 아래 칸으로 내려가야 합니다. 이 때 각 칸에 적혀 있는 숫자만큼 오른쪽이나 아래 칸으로 움직일 수 있으며, 중간에 게임판 밖으로 벗어나면 안 됩니다. 균형을 잃어서 다른 발로 서거
www.algospot.com
jumpgame
DP문제
