#include <iostream>
#include <string>
#define YES "YES"
#define NO "NO"
using namespace std;
int Jump(int y, int x);
int n, board[100][100];
int cache[100][100];
int main()
{
int c, cnt=0;
string solution[50];
for (int i = 0; i < 100; i++)
for (int j = 0; j < 100; j++)
cache[i][j] = -1;
cin >> c;
if (c > 50)
return -1;
for (int i = 0; i < c; i++)
{
cin >> n;
if (n < 2 || n > 100)
return -1;
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
cin >> board[j][k];
}
}
if (Jump(0, 0) == 1)
solution[cnt++] = YES;
else
solution[cnt++] = NO;
}
for (int i = 0; i < cnt; i++)
cout << solution[i] << endl;
}
int Jump(int y, int x)
{
if (y >= n || x >= n) return 0;
if (y == n-1 && x == n-1) return 1;
int& ret = cache[y][x];
if (ret != -1) return ret;
int jumpSize = board[y][x];
return ret = (Jump(y + jumpSize, x) || Jump(y, x + jumpSize));
}
위와 같이 책보고 코드 작성했는데ㅠ 왜 계속 오답이 나오는 지 ...
답변 부탁드려요
10년 전
0개의 댓글이 있습니다.
정회원 권한이 있어야 커멘트를 다실 수 있습니다. 정회원이 되시려면
온라인 저지에서 5문제 이상을 푸시고, 가입 후 7일 이상이 지나셔야
합니다. 현재 문제를 푸셨습니다.
sihon321
위와 같이 책보고 코드 작성했는데ㅠ 왜 계속 오답이 나오는 지 ...
답변 부탁드려요
10년 전