파이썬59 [백준 1450] 냅색문제 - Python(파이썬) from bisect import bisect_left import sys N, C = map(int, sys.stdin.readline().split()) things = list(map(int, sys.stdin.readline().split())) data1 = [0] data2 = [0] if N % 2: for i in range(N // 2): temp = [] for x in data1: temp.append(things[i] + x) data1 += temp for i in range(N // 2, N): temp = [] for x in data2: temp.append(things[i] + x) data2 += temp else: for i in range(N // 2): temp = .. 2021. 4. 3. [백준 9252] LCS 2 - Python(파이썬) import sys def solution(): answer = '' for i in range(len(str1)): temp = '' for j in range(len(str2)): if len(temp) < len(check[j]): temp = check[j] elif str1[i] == str2[j]: check[j] = temp + str1[i] for ck in check: if len(answer) < len(ck): answer = ck if len(answer): print(len(answer), answer, sep='\n') else: print(0) str1 = sys.stdin.readline().strip() str2 = sys.stdin.readline().strip() che.. 2021. 4. 3. [백준 14003] 가장 긴 증가하는 부분 수열 5 - Python(파이썬) import sys from bisect import bisect_left N = int(sys.stdin.readline()) data = list(map(int, sys.stdin.readline().split())) check = [0] temp = [data[0]] for i in range(1, N): x = data[i] if temp[-1] < x: temp.append(x) check.append(len(temp) - 1) else: idx = bisect_left(temp, x) temp[idx] = x check.append(idx) print(len(temp)) cnt = max(check) answer = '' for i in range(N-1, -1, -1): if check[i].. 2021. 4. 3. [백준 14002] 가장 긴 증가하는 부분 수열 4 - Python(파이썬) import sys A = int(sys.stdin.readline().strip()) data = list(map(int, sys.stdin.readline().split())) check = [1] * A for i in range(A-1, -1, -1): for j in range(i-1, -1, -1): if data[i] > data[j] and check[i] >= check[j]: check[j] += 1 key = max(check) print(key) for i in range(A): if check[i] == key: print(data[i], end=' ') key -= 1 2021. 4. 3. [백준 1644] 소수의 연속합 - Python(파이썬) import sys def check(digit): data = [True] * (digit + 1) for i in range(2, int(digit ** 0.5) + 1): if data[i]: data[2 * i::i] = [False] * ((digit - i) // i) return [i for i in range(2, digit + 1) if data[i]] N = int(sys.stdin.readline().strip()) prime_number = check(N) prime_number.append(0) start, end = 0, 1 my_sum = prime_number[0] answer = 0 while start < end < len(prime_number): if my_sum ==.. 2021. 4. 3. [백준 1806] 부분합 - Python(파이썬) 투 포인터를 활용한 코드 import sys N, S = map(int, sys.stdin.readline().split()) data = list(map(int, sys.stdin.readline().split())) + [0] start, end = 0, 1 answer = float('inf') temp = data[0] while start = S: if answer > end - start: answer = end - start temp -= data[start] start += 1 else: temp += data[end] end += 1 print(answer if answer != float('inf') else 0) 2021. 3. 31. 이전 1 2 3 4 ··· 10 다음