문제링크:https://www.acmicpc.net/problem/2110 import sys N, C = map(int, sys.stdin.readline().split()) home = [] for _ in range(N): home.append(int(sys.stdin.readline())) home.sort() # 이분 탐색을 위해 정렬 start = 0 end = home[-1] ans = 0 def binary(arr, s, e): while s = current + m: # arr[i]보다 작거나 같으면 count +=1 공유기를 arr[i]에 설치 count += 1 current = arr[i] if count >= C: # C를 넘어가면 더 넓게 설치할수있다는 말 => s = m+1 g..
문제링크:https://www.acmicpc.net/problem/10971 import sys input = sys.stdin.readline n = int(input()) costs = [list(map(int, input().split())) for _ in range(n)] visited = [0] * n # 방문했는지 안했는지 sum_cost = 0 # 방문비용 합 ans = sys.maxsize def dfs(depth, x): global sum_cost, ans if depth == n - 1: # 종료 조건 if costs[x][0]: sum_cost += costs[x][0] if sum_cost < ans: # 최소값 비교 ans = sum_cost sum_cost -= costs[x..
문제링크:https://www.acmicpc.net/problem/10819 import sys import itertools # N개의 정수로 이루어진 리스트 입력받기 N = int(sys.stdin.readline()) A = list(map(int, sys.stdin.readline().split())) # permutations 메소드는 가능한 순열들의 조합을 튜플로 생성해 해당 레퍼런스를 반환한다. per = itertools.permutations(A) res = 0 for i in per: s = 0 # per안의 순열들의 차이(s)를 구해 s가 res보다 클시에 업데이트 for j in range(1, N): s += abs(i[j - 1] - i[j]) if res < s: res = s..
문제링크:https://www.acmicpc.net/problem/9663 # limitation - 백트레킹 함수 > 퀸이 같은 행렬에 있으면 안됨, 퀸이 대각선에 있으면 안됨 false일시 그행 제외 # 입력 N은 NxN 체스판 row[0]*n 으로 사용 # result - > =+ 로 출력할 방법갯수 카운팅 # 출력 퀸을 놓을수있는 방법 출력 # import sys n = int(sys.stdin.readline()) row = [0] * n cnt = 0 #퀸을 놓고 그 이후 놓기 불가능한 줄 찾기 def prommising(a): for i in range(a): if row[a] == row[i] or abs(row[a] - row[i]) == abs(a - i): return False re..
문제링크:https://www.acmicpc.net/problem/1914 import sys n = int(sys.stdin.readline()) # n: 원판 갯수 , 1번기둥(start) - s기둥, 2번 기둥(middle) - m 기둥, 3번 기둥(end) - e 기둥 def hanoi(n, s, e): m = 6 - s - e # 2번기둥 if n == 1: print(s, e) # else: hanoi(n - 1, s, m) # n-1 의 원판을 전부 s -> m (그 안에서 print 1,3 -> 1,2 -> 3,2...) print(s, e) #남은 하나를 s -> e 1,3 hanoi(n - 1, m, e) # m에 위치한 n-1의 원판을 전부 -> e로 print(2 ** n - 1) ..
문제링크:https://www.acmicpc.net/problem/2628 import sys paper = list(map(int, sys.stdin.readline().split())) # paper 는 종이 가로 세로 입력 t = int(sys.stdin.readline()) width = [0, paper[0]] # width는 가로 길이 *미리 0이 들어가있는 것이 중요!!* height = [0, paper[1]] # height는 세로 길이 *미리 0이 들어가있는 것이 중요!!* #이유 -> 종이를 xy로 생각했을떄 0,0 좌표가 있어야 최대 넓이값 구할떄 오류 발생 x for _ in range(t): # t는 테스트 케이스 수 c = list(map(int, sys.stdin.readli..