탐색2 정올 JAVA - 벽장문의 이동 (1409) 백트래킹 https://beta.jungol.co.kr/problem/1409?cursor=eyJwcm9ibGVtc2V0Ijo4LCJmaWVsZCI6MiwiaWR4Ijo1fQ== 1. rec(열어야할 벽장 위치, 비용(현재 벽장 위치 - 열려있는 벽장 위치), 열린 곳01, 열린 곳 02) 2. 비용이 구해놓은 최솟값보다 크면 더이상 탐색하지 않고 돌아간다. import java.util.Scanner; import java.util.ArrayList; public class Main { static int n; static int open1, open2; static int go; static int answer = 0x7fffffff; static ArrayList arr = new ArrayList(); s.. 2023. 5. 11. 정올 C++ - 해밀턴 순환회로(1681) DFS, 백트래킹 https://beta.jungol.co.kr/problem/1681?cursor=eyJwcm9ibGVtc2V0Ijo4LCJmaWVsZCI6MiwiaWR4IjoxfQ== 1. 더 이상 탐색하지 않아도 되는 경우를 파악한다. 1) 이동 비용이 구했던 최솟값(ans)보다 크다면 return 2) 갔던 장소는 또 다시 가지 않는다. #pragma warning(disable:4996) #include #include using namespace std; int graph[15][15], n; int freq[15], ans = 0x7fffffff; void dfs(int level, int cost, int cnt) // 장소, 비용, 이동 횟수 { if (ans < cost) return; // 비용이 구했.. 2023. 5. 2. 이전 1 다음