일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
- 에라토스테네스의 체
- 누적합
- join
- 분할정복
- 다익스트라
- 브루트포스
- 시뮬레이션
- 트리
- 그래프 이론
- 다이나믹프로그래밍
- 서브쿼리
- 수학
- 플로이드-워셜
- 그리디
- 그래프 탐색
- 해시
- MST
- 우선순위큐
- 구현
- 투포인터
- 다시
- 백트래킹
- DP
- 자료구조
- BFS
- DFS
- 재귀
- 다이나믹 프로그래밍
- GROUP BY
- 크루스칼
- Today
- Total
목록DFS (15)
기록하고 까먹지 말기

날짜 : 2023. 10. 19 사용 언어 : python 문제 코드 import sys def dfs(idx, nums): # print(type(nums)) if len(nums) == m: for i in range(m): print(nums[i], end=" ") print() return before = -1 for i in range(idx, n): if i == idx + 1: before = arr[idx] if before == arr[i]: continue nums.append(arr[i]) dfs(i, nums) nums.pop() n, m = map(int, sys.stdin.readline().split()) arr = list(map(int, sys.stdin.readline()..

날짜 : 2023. 10. 08 사용 언어 : python 문제 코드 def solution(info, edges): visited = [False] * len(info) # 방문처리 res = list() visited[0] = True res.append(1) def dfs(sheep, wolf): if sheep > wolf: res.append(sheep) else: return for start, end in edges: if visited[start] and not visited[end]: # 부모노드 방문 완료, 자식노드 탐색 visited[end] = True # 방문처리 if info[end] == 0: # 자식이 양 dfs(sheep + 1, wolf) else: dfs(sheep, w..

날짜 : 2023. 09. 30 사용 언어 : python 문제 코드 import sys def bt(idx, path): if len(path) == m: if path not in res: res.append(path) return for i in range(idx, n): bt(i, path + [a[i]]) return n, m = map(int, sys.stdin.readline().split()) a = list(map(int, sys.stdin.readline().split())) a.sort() # print(a) res = list() bt(0, []) res.sort() for i in res: print(*i) 풀이 - 기본적인 백트래킹을 활용한 문제 - 조건에 따라 입력받은 후 해당..

날짜 : 2023. 09. 29 사용 언어 : python 문제 코드 def solution(tickets): used = [False] * len(tickets) # 사용여부 res = list() def dfs(now, path): # print(now, path) if len(path) == len(tickets) + 1: res.append(path) return for i in range(len(tickets)): if not used[i] and tickets[i][0] == now: # 현재 체크하는 티켓 사용 x, 출발지가 동일 used[i] = True # 사용체크 dfs(tickets[i][1], path + [tickets[i][1]]) # 리스트간 더하기 used[i] = False..

날짜 : 2023. 09. 13 사용 언어 : python 문제 코드 def dfs(row, depth): cnt = 0 # 개수 저장용 if depth == len(row): # 마지막 행까지 도달 return 1 for i in range(len(row)): row[depth] = i # 해당 row에서 퀸을 위치시켰을 때 for j in range(depth): if row[depth] == row[j] : break # 같은 열인지 체크 if abs(row[depth] - row[j]) == (depth - j): break # 대각선인지 체크 else: cnt += dfs(row, depth+1) return cnt def solution(n): row = [0] * n # 리스트 row의 i번..

날짜 : 2023. 09. 03 사용 언어 : python 문제 코드 import sys n, m = map(int, sys.stdin.readline().split()) nums = list(map(int, sys.stdin.readline().split())) nums.sort() res = list() visited = [False] * n def bt(depth): if depth == m: print(*res) return for i in range(n): if not visited[i]: visited[i] = True res.append(nums[i]) bt(depth + 1) res.pop() visited[i] = False bt(0) 풀이 - 일반적인 백트래킹 방식으로 풀이한다 알게된 ..

날짜 : 2023. 08. 31 사용 언어 : python 문제 코드 import sys n, m = map(int, sys.stdin.readline().split()) nums = list(map(int, sys.stdin.readline().split())) nums.sort() res = list() visited = [False] * n def bt(depth): if depth == m: print(*res) return prev = 0 for i in range(n): if not visited[i] and prev != nums[i]: prev = nums[i] # 수열의 최신 원소 visited[i] = True # 방문처리 res.append(prev) bt(depth + 1) visi..