본문 바로가기

전체 글

(102)
[Algorithm|Python] 백준 1351번 from collections import defaultdictimport sysinput = sys.stdin.readlinedef dfs(n): if data[n] != 0: return data[n] data[n] = dfs(n // p) + dfs(n // q) return data[n]if __name__ == "__main__": n, p, q = map(int, input().split()) data = defaultdict(int) data[0] = 1 print(dfs(n))
[Algorithm|Python] 백준 2225번 import sysinput = sys.stdin.readlinen, k = map(int,input().split())dp = [[0] * 201 for _ in range(201)]for i in range(201): dp[1][i] = 1 dp[2][i] = i+1for i in range(3, 201): dp[i][1] = i for j in range(2, 201): dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % 1000000000print(dp[k][n])
[Algorithm|Python] 백준 9251번 s1 = list(input())s2 = list(input())lcs = [[0] * (len(s2) + 1) for _ in range(len(s1) + 1)]for i in range(1, len(s1)+1): for j in range(1, len(s2)+1): if s1[i-1] == s2[j-1]: lcs[i][j] = lcs[i-1][j-1] + 1 else: lcs[i][j] = max(lcs[i-1][j], lcs[i][j-1]) print(max(map(max,lcs)))
[Algorithm|Python] 백준 11053번 import sysinput = sys.stdin.readline N = int(input()) A = list(map(int, input().split()))dp = [1] * N for i in range(1, N): for j in range(i): if A[i] > A[j]: dp[i] = max(dp[i], dp[j]+1) print(max(dp))
[Python|Algorithm] 백준 1003번 파이썬 T = int(input())for _ in range(T): N = int(input()) a, b = 1, 0 for i in range(N): a,b = b, a+b print(a,b)
[Algorithm|Python] 백준 19598번 / 99클럽 20일차 TIL import sysimport heapq as hqinput = sys.stdin.readlinen = int(input())times = []for _ in range(n): times.append(list(map(int, input().split()))) times.sort(key=lambda x:x[0])arr = [0]count = 1for start, end in times: if start >= arr[0]: hq.heappop(arr) else: count += 1 hq.heappush(arr, end)print(count)
[Algorithm|Python] 백준 1946번 / 99클럽 19일차 TIL import sysinput = sys.stdin.readlineT = int(input())for _ in range(T): N = int(input()) rank = [list(map(int, input().split())) for _ in range(N)] rank_asc = sorted(rank) top = 0 result = 1 for i in range(1, len(rank_asc)): if rank_asc[i][1]
[Algorithm|Python] 백준 147503번 / 99클럽 18일차 from heapq import heappop, heappushimport sysinput = sys.stdin.readline N, M, K = map(int, input().split())beers = []for _ in range(K): v, c = map(int, input().split()) beers.append([v, c]) beers.sort(key=lambda x: x[1]) def solution(): picked = [] preference = 0 for b in beers: heappush(picked, b) preference += b[0] if len(picked) >= N: if prefere..