티스토리 뷰

알고리즘/SWEA

[SWEA 1211] Ladder2

히더 2018. 8. 6. 17:37

출처 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14BgD6AEECFAYh


#include <iostream>

#include <algorithm>

#include <memory.h>

using namespace std;


int result,r;

int arr[100][102], a, b;

bool visited[100][102];


void cal(int ii, int jj,int cnt)

{

if (ii == 0)

{

if (result >= cnt) { result = cnt; r = jj - 1; }

return;

}

visited[ii][jj] = true; cnt++;

if (arr[ii][jj + 1] && !visited[ii][jj+1]) cal(ii, jj + 1,cnt);

else if (arr[ii][jj - 1] && !visited[ii][jj - 1]) cal(ii, jj - 1,cnt);

else if (arr[ii-1][jj] && !visited[ii-1][jj]) cal(ii-1, jj,cnt);

}


int main()

{

int T; int t;

T = 10;

while (T--)

{

cin >> t; result = 9999999; memset(arr, 0, sizeof(arr)); 

for (int i = 0; i < 100; i++)for (int j = 1; j <= 100; j++)

{

cin >> arr[i][j];

if (i == 99)

{

memset(visited, false, sizeof(visited));

cal(i, j,0);

}

}


cout << "#" << t << " " << r << endl;

}


return 0;

}


'알고리즘 > SWEA' 카테고리의 다른 글

[SWEA 1215] 회문1  (0) 2018.08.09
[SWEA 1213] String  (0) 2018.08.09
[SWEA 1210] Ladder1  (0) 2018.08.06
[SWEA 1209] Sum  (0) 2018.08.06
[SWEA 1204] 최빈수 구하기  (0) 2018.08.06
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
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
글 보관함