본문 바로가기

분류 전체보기265

2025 프로그래머스 코드챌린지 1차 예선 > 비밀 코드 해독 - Python, combinations https://school.programmers.co.kr/learn/courses/30/lessons/388352 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr  코드 & 풀이 from itertools import combinationsdef solution(n, q, ans): possible_code = list(combinations(range(1, n + 1), 5)) total_cnt = 0 for code in possible_code: make_code = True for i in range(len(q)): if len.. 2025. 3. 7.
트리의 부모 찾기 - Python, BFS, 재귀 깊이 제한 키우기 출처 : https://www.acmicpc.net/problem/11725   코드 import sysfrom collections import deque, defaultdictdef find_parents(N, edges): graph = defaultdict(list) for a, b in edges: graph[a].append(b) graph[b].append(a) parent = [0] * (N + 1) visited = [False] * (N + 1) q = deque([1]) visited[1] = True while q: node = q.popleft() for neighbor in graph[node.. 2025. 3. 7.
2022 KAKAO BLIND RECRUITMENT > 주차 요금 계산 - Python, ceil(올림), defaultdict 주소 코드 & 풀이 from collections import defaultdictimport mathdef solution(fees, records): in_times = defaultdict(int) # 입고 시간 total_times = defaultdict(int) # 주차 시간 last_time = (23 * 60) + 59 # 23:59 def set_time_to_minute(times): time, minute = map(int,times.split(":")) return time * 60 + minute for record in records: time, car_number, order = rec.. 2025. 3. 1.
배낭 문제(Knapsack Problem) 제한된 용량을 가진 상태에서 여러 개의 아이템을 선택하여 최대 가치를 구하는 방식입니다. 이때 아이템의 무게를 나눌 수 있는지 없는지로 나눠집니다. 1. 0-1 배낭 문제 각 아이템은 선택하거나(1) 선택하지 않거나(0) 두 가지 경우만 존재할 경우DP를 사용하여 해결하며, 시간 복잡도는 O(nW)문제 정의배낭의 최대 용량이 Wn개의 아이템이 있으며, 각 아이템 i는 무게 w[i]와 가치 v[i]를 가진다.배낭에 넣을 수 있는 최대 가치를 구하는 것이 목표이다. 코드# 0-1 Knapsack Problem (Dynamic Programming)def knapsack_01(W, weights, values, n): dp = [[0] * (W + 1) for _ in range(n + 1)] .. 2025. 2. 28.
[PCCP 기출문제] 2번 > 석유 시추 - Python, bfs, 누적합 https://school.programmers.co.kr/learn/courses/30/lessons/250136 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr  코드 & 풀이 from collections import dequedef solution(land): n, m = len(land), len(land[0]) visited = [[False] * m for _ in range(n)] def find_oil(i, j): direct = [(-1, 0), (1, 0), (0, -1), (0, 1)] q = deque([(i, j)]).. 2025. 2. 27.
[PCCP 기출문제] 3번 > 충돌위험 찾기 - Python, Counter https://school.programmers.co.kr/learn/courses/30/lessons/340211 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr  코드 & 풀이 from collections import Counterdef solution(points, routes): # 출발지부터 도착지까지 검사해야 됨 # 출발지에서 검사 한 번 하고 시작 or 공회전 한 번 돌리고 시작 new_routes = [] for route in routes: step = 0 x, y = points[route[0] - 1] tmp_route = .. 2025. 2. 27.