목록백준 문제 풀이 (154)
황소개발자
import sys input = sys.stdin.readline n = int(input()) days = [] for i in range(n): days.append(list(map(int, input().split()))) ans = -999999999 def go(day, total): global ans if day == n: # n에 알맞게 도착했을 때, 정답이 될 수 있다. ans = max(ans, total) return if day > n: # n을 초과한다면 범위 안에 일을 못끝내므로, 정답이 될 수 없다. return go(day + 1, total) # 이번 day는 일을 하지 않고 그냥 넘어간다! go(day + days[day][0], total + days[day][1]) ..
import sys input = sys.stdin.readline n, s = map(int, input().split()) lst = list(map(int, input().split())) ans = 0 def sub_sum(idx, total): global ans, s if idx == n: if total == s: ans += 1 return sub_sum(idx + 1, total) sub_sum(idx + 1, total + lst[idx]) sub_sum(0, 0) ans -= 1 if s == 0 else 0 print(ans)
import sys input = sys.stdin.readline def next_permutation(lst): n = len(lst) i = n - 1 while i > 0 and lst[i - 1] >= lst[i]: i -= 1 if i == 0: return [-1] j = n - 1 while lst[i - 1] >= lst[j]: j -= 1 tmp = lst[j] lst[j] = lst[i - 1] lst[i - 1] = tmp lst = lst[:i] + sorted(lst[i:]) return lst L, C = map(int, input().split()) lst = input().split() lst.sort() bit = [0] * (C - L) + [1] * L bites = ..
import sys input = sys.stdin.readline def next_permutation(lst): n = len(lst) i = n - 1 while i > 0 and lst[i - 1] >= lst[i]: i -= 1 if i == 0: return [-1] j = n - 1 while lst[i - 1] >= lst[j]: j -= 1 tmp = lst[j] lst[j] = lst[i - 1] lst[i - 1] = tmp lst = lst[:i] + sorted(lst[i:]) return lst while True: s = input().strip() if s == '0': break lst = list(map(int, s.split())) n = lst[0] lst = lst[..
n = int(input()) mat = [] for i in range(n): mat.append(list(map(int, input().split()))) def next_permutation(lst): n = len(lst) i = n - 1 while i > 0 and lst[i - 1] >= lst[i]: i -= 1 if i == 0: return [-1] j = n - 1 while lst[i - 1] >= lst[j]: j -= 1 tmp = lst[j] lst[j] = lst[i - 1] lst[i - 1] = tmp lst = lst[:i] + sorted(lst[i:]) return lst pathes = [] path = [i for i in range(2, n + 1)] while..
import sys input = sys.stdin.readline n = int(input()) lst = list(map(int, input().split())) lst.sort() def next_permutation(lst): n = len(lst) i = n - 1 while i > 0 and lst[i - 1] >= lst[i]: i -= 1 if i == 0: return [-1] # i - 1 j = n - 1 while lst[j]
n = int(input()) def next_permutation(lst): n = len(lst) i = n - 1 while i > 0 and lst[i - 1] >= lst[i]: i -= 1 if i