Python 3

[완전탐색][상태 트리] - 휴가(DFS)

풀이 def DFS(L, money, day): global res if day > n: return if day == n: if res < money: res = money else: DFS(L+1, money + schedule[day][1], day + schedule[day][0]) DFS(L+1, money, day+1) if __name__ =="__main__": n = int(input()) schedule = [] for _ in range(n): a, b = map(int,input().split()) schedule.append([a,b]) res = -2147000000 DFS(0,0,0) print(res) 설명 schedule.append([a,b]) - schedule[변수][..

[프로그래머스][Lv2] - 소수 찾기(파이썬/Python)

from itertools import permutations def solution(numbers): a = set() #중복을 방지하기 위해서 set으로 설정 #순열을 사용해서 사용가능한 조합을 모두 찾아준 뒤 진행한다. for i in range(len(numbers)): a |= set(map(int, map("".join, permutations(list(numbers), i + 1)))) a -= set(range(0,2)) for i in range(2,int(max(a)**0.5)+1): a -= set(range(i*2,max(a)+1,i)) return len(a)

[프로그래머스][Lv2] - 다리를 지나는 트럭(파이썬/Python)

from collections import deque def solution(bridge_length, weight, truck_weights): time = 0 b = deque([0 for _ in range(bridge_length)]) w = 0 #다리 위의 무게 q = deque(truck_weights) while len(q) > 0 or w > 0: #지워주는 작업부터 시작. # 0으로 초기화 해주어서 popleft의 문제가 생기지 않는 것. removeTruck = b.popleft() w -= removeTruck if len(q) and q[0] + w