왜 안 되는데
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <malloc.h>
//int n;
int d = 1, count = 0; //방향, 총 획득 점수
int x = 1, y = 1;
int N, M, K; //세로, 가로, 횟수
int kount = 0; //방문 횟수 카운트
//int can = 4;
int dice[7];
int map[21][21], dojang[21][21];
//int abs(int a) { return a >= 0 ? a : -a; } //절댓값 함수
//남, 아래쪽
void south()
{
dice[6] = dice[3];
dice[3] = dice[2];
dice[2] = dice[1];
dice[1] = dice[0];
dice[0] = dice[6];
y++;
}
//북, 위쪽
void north()
{
dice[6] = dice[0];
dice[0] = dice[1];
dice[1] = dice[2];
dice[2] = dice[3];
dice[3] = dice[6];
y--;
}
//동, 오른쪽
void east()
{
dice[6] = dice[1];
dice[1] = dice[4];
dice[4] = dice[3];
dice[3] = dice[5];
dice[5] = dice[6];
x++;
}
//서쪽, 왼쪽
void west()
{
dice[6] = dice[1];
dice[1] = dice[5];
dice[5] = dice[3];
dice[3] = dice[4];
dice[4] = dice[6];
x--;
}
//방향 정하는 규칙
void direction()
{
if (dice[3] > map[x][y]) //dice 밑바닥이 판 숫자보다 크면
{
if (d >= 4) d = 1; //북쪽이었으면 동쪽으로
else d++; //사실 시계방향으로 회전
}
else if (dice[3] < map[x][y])
{
if (d <= 1) d = 4; //동쪽이었으면 북쪽으로
else d--; //사실 반시계방향으로 회전
}
if (x == M && d == 1) d = 3; //칸의 끝이면 반대로 한 칸
if (x == 1 && d == 3) d = 1;
if (y == N && d == 2) d = 4;
if (y == 1 && d == 4) d = 2;
}
//점수를 획득하기 위한 사방 탐색
void wasd(a, b)
{
if ((a + 1 <= M) && (dojang[a + 1][b] == 0)) //동쪽을 방문 안 했을 때
{
if (map[a + 1][b] == map[x][y]) //같은 점수면 도장 1
{
dojang[a + 1][b] = 1;
wasd(a + 1, b); //그쪽으로 가서 상하좌우 탐색
}
else dojang[a + 1][b] = 2; //다른 점수면 도장 2
}
if ((b + 1 <= N) && (dojang[a][b + 1] == 0))
{
if (map[a][b + 1] == map[x][y])
{
dojang[a][b + 1] = 1;
wasd(a, b + 1);
}
else dojang[a + 1][b] = 2;
}
if ((a - 1 >= 1) && (dojang[a - 1][b] == 0))
{
if (map[a - 1][b] == map[x][y])
{
dojang[a - 1][b] = 1;
wasd(a - 1, b);
}
else dojang[a - 1][b] = 2;
}
if ((b - 1 >= 1) && (dojang[a][b - 1] == 0))
{
if (map[a][b - 1] == map[x][y])
{
dojang[a][b - 1] = 1;
wasd(a, b - 1);
}
else dojang[a][b - 1] = 2;
}
//새로 갈 곳이 아무데도 없으면 왔던 함수 호출 아랫줄(전단계 다른 방향) 탐색
}
//도착했을 때 점수 획득하기
void jumsu(x, y)
{
for (int i = 1; i <= M; i++)
for (int j = 1; j <= N; j++)
dojang[i][j] = 0;
dojang[x][y] = 1;
wasd(x, y);
int s = 0;
for (int i = 1; i <= M; i++)
for (int j = 1; j <= N; j++)
if (dojang[i][j] == 1) s++;
count = count + s * map[x][y];
}
//들어온 숫자에 따라 방향을 정해 한칸 가기
void game(d)
{
if (kount >= K) return;
if (d == 1)
east();
else if (d == 2)
south();
else if (d == 3)
west();
else if (d == 4)
north();
kount++;
jumsu(x, y); //점수 획득
direction(); //방향 설정
game(d);
}
int main()
{
dice[0] = 2;
dice[1] = 1; //윗면
dice[2] = 5;
dice[3] = 6; //바닥면
dice[4] = 4; //좌
dice[5] = 3; //우
scanf("%d %d %d ", &N, &M, &K);
for (int j = 1; j <= N; j++)
for (int i = 1; i <= M; i++)
scanf("%d ", &map[i][j]);
game(1);
printf("%d", count);
getchar();
getchar();
getchar();
return 0;
}