dfs 5

[백준] 13305번 : 주유소 (python 파이썬)

https://www.acmicpc.net/problem/13305  from collections import dequeimport sysn = int(input())road = list(map(int, sys.stdin.readline().split(" "))) #도로의 길이oil = list(map(int, sys.stdin.readline().split(" "))) # 주유소의 기름 가격graph = [[oil[0],0]] #[기름가격의 최솟값, 주요소까지의 거리]min_oil = oil[0]length = 0for i in range(len(road)): if oil[i] = length: print(cost) break if oil  문제 설명n개의 도시가 ..

[프로그래머스] 양과 늑대 [Level 3] (python 파이썬)

https://school.programmers.co.kr/learn/courses/30/lessons/92343 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr    from collections import dequedef solution(info, edges): visit = [0 for i in range(len(info))] graph = [[] for i in range(len(info))] for edge in edges: graph[edge[0]].append(edge[1]) visit[0] = 1..

[프로그래머스] 여행경로 [Level 3] (python 파이썬) [BFS]

https://school.programmers.co.kr/learn/courses/30/lessons/43164 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr     from collections import dequedef solution(tickets): d= deque() n = len(tickets) for i in range(n): if tickets[i][0] == "ICN": visit = [0 for i in range(n)] visit..

[백준] 21736번 : 헌내기는 친구가 필요해 [BFS 설명 有]

https://www.acmicpc.net/problem/21736 21736번: 헌내기는 친구가 필요해2020년에 입학한 헌내기 도연이가 있다. 도연이는 비대면 수업 때문에 학교에 가지 못해 학교에 아는 친구가 없었다. 드디어 대면 수업을 하게 된 도연이는 어서 캠퍼스 내의 사람들과 친해지고www.acmicpc.net        import sysfrom collections import deque n, m = map(int, sys.stdin.readline().split(" "))l = []a,b = 0, 0for i in range(n): l2 = list(sys.stdin.readline().strip()) if 'I' in l..

[프로그래머스] 타겟 넘버 [Level 2] (python 파이썬) (DFS,BFS)

https://school.programmers.co.kr/learn/courses/30/lessons/43165 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr  #DFS로 푸는 경우def solution(numbers, target): ans = 0 def dfs(num, index): nonlocal ans if index == len(numbers): if num == target: ans = ans +1 ..

반응형