[백준] 1103번: 게임
·
PS/Baekjoon
문제https://www.acmicpc.net/problem/1103설명 전형적인 그래프 탐색 문제이지만, 사이클이 발생한 경우를 탐지해야 하므로 BFS 대신 DFS를 사용하는 것이 효율적이다. 그러나 단순히 DFS를 수행하며 동전이 움직일 수 있는 최대 횟수를 구하려고 하면 시간 초과가 발생하게 된다. 이미 방문한 지점인 경우, 추가적인 탐색을 진행하면 안 된다. 따라서 DP 배열을 추가로 선언해야 한다.코드더보기#include #include using namespace std;int ans = 0;bool cycleFlag = false;int n, m;int board[50][50];int visited[50][50];int cnt[50][50];int dx[4] = { -1,0,1,0 };int..