#include<stdio.h>
void init_cache(int(*cache)[101]);
int jump(int (*cache)[101],int(*map)[101], int x, int y, int n);
int main()
{
//freopen("input.txt", "r", stdin);
int tc, t;
int n, i, j;
int map[101][101];
int cache[101][101];
scanf("%d", &tc);
for (t = 1; t <= tc; t++) {
init_cache(cache);
scanf(" %d", &n);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
scanf(" %d", &map[i][j]);
}
}
if (jump(cache, map, 0, 0, n)>0)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
void init_cache(int(*cache)[101])
{
int i, j;
for (i = 0; i < 101; i++) {
for (j = 0; j < 101; j++) {
cache[i][j] = -1;
}
}
}
int jump(int(*cache)[101], int(*map)[101], int x, int y, int n)
{
int move = map[x][y];
int *ret = &(cache[x][y]);
if (x < 0 || y < 0 || x >= n || y >= n)
return 0;
if (x == n - 1 && y == n - 1)
return 1;
if (*ret != -1)
return *ret;
*ret = 0;
*ret = jump(cache,map, x + move, y, n) + jump(cache,map, x, y + move, n);
return *ret;
}
gzone130
종만북 보고 공부중입니다.
C를 이용해서 아래와 같이 코드를 짜봤습니다.
정답이랑은 제대로 나오는데 문제를 돌리면 틀렸다고 나옵니다..
도대체 어디서 문제가 되는 건지 감이 잡히질 않습니다.
도와주세요!
8년 전