๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ

โœ… ์žฌ๊ท€ ํ’€์ด answer=0def dfs(numbers,target,cur_idx,cur_total): global answer # ํƒˆ์ถœ ์กฐ๊ฑด(๋ชจ๋“  ์ˆ˜ ์ˆœํšŒ) if cur_idx==len(numbers): if cur_total==target: answer+=1 return else: dfs(numbers,target,cur_idx+1,cur_total+numbers[cur_idx]) dfs(numbers,target,cur_idx+1,cur_total-numbers[cur_idx])def solution(numbers, target): global answer dfs(numbers,target,0,..
https://school.programmers.co.kr/learn/courses/30/lessons/154540 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.programmers.co.kr  โœ… DFS ํ’€์ดimport syssys.setrecursionlimit(10**6)dx = [1, -1, 0, 0]dy = [0, 0, -1, 1]def dfs(x, y, graph): count = graph[x][y] # ํ˜„์žฌ ์œ„์น˜ ์‹๋Ÿ‰๊ฐ’ graph[x][y] = 0 # ๋ฐฉ๋ฌธ ์ฒ˜๋ฆฌ for d in range(4): nx = x + dx[d] ny =..
โŽ 1์ฐจ ํ’€์ดfrom itertools import productdef solution(n): num_list = [1, 2] count = 0 for i in range(1, n + 1): for perm in product(num_list, repeat=i): if sum(perm) == n: count += 1 continue return count % 1234567๋ชจ๋“  ์กฐํ•ฉ์„ ์ค‘๋ณต์ด ๊ฐ€๋Šฅํ•œ product๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋งŒ๋“ค๊ณ , ๊ทธ ํ•ฉ์ด n์ด ๋˜๋ฉด ์นด์šดํŠธ๋ฅผ ์ฆ๊ฐ€์‹œํ‚ค๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ํ•ด๋ณด์•˜๋‹ค. ์—ญ์‹œ๋‚˜, ์‹œ๊ฐ„์ดˆ๊ณผ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€๋‹ค.  ์ด ๋ฌธ์ œ ์นดํ…Œ๊ณ ๋ฆฌ๊ฐ€ DP์ธ๋ฐ, ๋™์ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋Œ€ํ‘œ์œ ํ˜•์ธ ํ”ผ๋ณด๋‚˜์น˜์™€ ๊ฐ™์€ ํŒจํ„ด์„..
๐ŸฅˆSilver 5 https://www.acmicpc.net/problem/10815  โœ… 1์ฐจ ํ’€์ดimport sysinput=sys.stdin.readlineanswer=''n=int(input())having_cards=set(map(int,input().rstrip().split()))m=int(input())num_list=list(map(int,input().rstrip().split()))for num in num_list: if num in having_cards: answer+='1' else: answer+='0'print(' '.join(answer))input์˜ ๋ฒ”์œ„๊ฐ€ 10^7์œผ๋กœ ์ด๋ถ„ํƒ์ƒ‰์„ ํ•ด์•ผํ•˜๋‚˜ ํ–ˆ์ง€๋งŒ, ์ผ๋‹จ ํ•œ๋ฒˆ ์ •์งํ•˜๊ฒŒ ํ’€์–ด๋ณด์•˜๋‹ค.์ƒ๊ทผ์ด..
https://school.programmers.co.kr/learn/courses/30/lessons/42747 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.programmers.co.kr โœ… ์ •๋‹ตํ’€์ด (Python)def solution(citations): citations.sort(reverse=True) h=0 for i in range(len(citations)): if citations[i]>=i+1: h=i+1 return hh๋ฒˆ ์ด์ƒ ์ธ์šฉ๋œ ๋…ผ๋ฌธ์ด hํŽธ์ด์ƒ์ด๋ผ๋Š” ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” h๊ฐ’ ์ค‘, ์ œ์ผ ํฐ h๊ฐ’์„ ์ฐพ์•„์•ผํ•œ..
https://school.programmers.co.kr/learn/courses/30/lessons/159994 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.programmers.co.kr โœ… ์ •๋‹ต ํ’€์ด Queue (Python)# ๊ฐ€์žฅ ๋งจ์•ž ์š”์†Œ๊ฐ€ ๋น ์ ธ๋‚˜๊ฐ€์•ผ ๋‹ค์Œ ์š”์†Œ๊ฐ€ ๋น ์ ธ๋‚˜๊ฐˆ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ -> queue ์‚ฌ์šฉfrom collections import dequedef solution(cards1, cards2, goal): first_cards=deque(cards1) sec_cards=deque(cards2) for word in goal: if fi..
https://school.programmers.co.kr/learn/courses/30/lessons/42628 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.programmers.co.kr โœ… 1์ฐจ ํ’€์ด import heapqdef solution(operations): heap = [] for operation in operations: [inst, value] = operation.split(' ') value = int(value) if inst == 'I': # heap ์‚ฝ์ž… heapq.hea..
https://school.programmers.co.kr/learn/courses/30/lessons/42626?language=python3 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.programmers.co.kr  โŽ 1์ฐจ ํ’€์ดimport heapqmin_heap = []def solution(scoville, K): heapq.heapify(scoville) count = 0 while scoville: # popํ•œ ๊ฐ’์ด k์ด์ƒ์ด๋˜๋ฉด, while ์ข…๋ฃŒ min_value = heapq.heappop(scoville) if mi..
Yuuuki
'๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก