diff --git "a/week1/datastructure/N\353\262\210\354\247\270_\355\201\260_\354\210\230/applied7076.py" "b/week1/datastructure/N\353\262\210\354\247\270_\355\201\260_\354\210\230/applied7076.py" deleted file mode 100644 index 96eb2f02..00000000 --- "a/week1/datastructure/N\353\262\210\354\247\270_\355\201\260_\354\210\230/applied7076.py" +++ /dev/null @@ -1,9 +0,0 @@ -n = int(input()) -li = [] - -for _ in range(n): - li += map(int, input().split()) - li.sort(reverse=True) - li = li[:n] - -print(li[n-1]) \ No newline at end of file diff --git "a/week1/datastructure/N\353\262\210\354\247\270_\355\201\260_\354\210\230/ss721229.py" "b/week1/datastructure/N\353\262\210\354\247\270_\355\201\260_\354\210\230/ss721229.py" deleted file mode 100644 index 645954a8..00000000 --- "a/week1/datastructure/N\353\262\210\354\247\270_\355\201\260_\354\210\230/ss721229.py" +++ /dev/null @@ -1,14 +0,0 @@ -import sys -input = sys.stdin.readline - -N = int(input()) -nums = list() - -for i in range(N): - nums.extend(list(map(int, input().split()))) - nums.sort(reverse=True) - len_nums = len(nums) - N - for j in range(len_nums): - nums.pop() - -print(nums[-1]) \ No newline at end of file diff --git "a/week1/datastructure/\352\264\204\355\230\270\354\235\230_\352\260\222/applied7076.py" "b/week1/datastructure/\352\264\204\355\230\270\354\235\230_\352\260\222/applied7076.py" deleted file mode 100644 index c6afe8aa..00000000 --- "a/week1/datastructure/\352\264\204\355\230\270\354\235\230_\352\260\222/applied7076.py" +++ /dev/null @@ -1,59 +0,0 @@ -from collections import deque - -s = input() -stack = deque() - -total = 0 -for item in s: - if item == '(' or item == '[': - stack.append(item) - else: - if item == ')': - if stack and stack[-1] == '(': - stack.pop() - stack.append(2) - else: - if "(" not in stack: - print(0) - exit(0) - inner = 0 - while stack: - top = stack.pop() - if top == '(': - stack.append(inner * 2) - break - elif top == '[': - print(0) - exit(0) - else: - inner += top - elif item == ']': - if stack and stack[-1] == '[': - stack.pop() - stack.append(3) - else: - if "[" not in stack: - print(0) - exit(0) - inner = 0 - while stack: - top = stack.pop() - if top == '[': - stack.append(inner * 3) - break - elif top == '(': - print(0) - exit(0) - else: - inner += top - - while len(stack) > 1: - if type(stack[-1]) == int and type(stack[-2]) == int: - stack.append(stack.pop() + stack.pop()) - else: - break - -if '(' in stack or '[' in stack: - print(0) -else: - print(sum(stack)) diff --git "a/week1/datastructure/\352\264\204\355\230\270\354\235\230_\352\260\222/ss721229.py" "b/week1/datastructure/\352\264\204\355\230\270\354\235\230_\352\260\222/ss721229.py" deleted file mode 100644 index 9618e1c6..00000000 --- "a/week1/datastructure/\352\264\204\355\230\270\354\235\230_\352\260\222/ss721229.py" +++ /dev/null @@ -1,37 +0,0 @@ -import sys -input = sys.stdin.readline - -st = input().rstrip() - -stack = list() -result = 0 -num = 1 - -for i in range(len(st)): - if st[i] == '(': - stack.append(st[i]) - num *= 2 - elif st[i] == '[': - stack.append(st[i]) - num *= 3 - elif st[i] == ')': - if not stack or stack[-1] == '[': - result = 0 - break - stack.pop() - if st[i - 1] == '(': - result += num - num //= 2 - elif st[i] == ']': - if not stack or stack[-1] == '(': - result = 0 - break - stack.pop() - if st[i - 1] == '[': - result += num - num //= 3 - -if stack: - print(0) -else: - print(result) \ No newline at end of file diff --git "a/week1/datastructure/\353\254\270\354\240\234_\354\266\224\354\262\234_\354\213\234\354\212\244\355\205\234_Version_1/applied7076.py" "b/week1/datastructure/\353\254\270\354\240\234_\354\266\224\354\262\234_\354\213\234\354\212\244\355\205\234_Version_1/applied7076.py" deleted file mode 100644 index 8144507c..00000000 --- "a/week1/datastructure/\353\254\270\354\240\234_\354\266\224\354\262\234_\354\213\234\354\212\244\355\205\234_Version_1/applied7076.py" +++ /dev/null @@ -1,47 +0,0 @@ -from heapq import heappop, heappush -import sys - -input = sys.stdin.readline -print = sys.stdout.write -maxProb = [] -minProb = [] -solvMaxProb = set() -solvMinProb = set() - -n = int(input()) -for i in range(n): - p, l = map(int, input().split()) - heappush(maxProb, (-l, -p)) - heappush(minProb, (l, p)) - -m = int(input()) -for i in range(m): - cmd = input().split() - - if cmd[0] == 'recommend': - x = int(cmd[1]) - if x == 1: - while -maxProb[0][1] in solvMaxProb: - solvMaxProb.remove(-maxProb[0][1]) - heappop(maxProb) - - print(str(-maxProb[0][1])) - print("\n") - else: - while minProb[0][1] in solvMinProb: - solvMinProb.remove(minProb[0][1]) - heappop(minProb) - - print(str(minProb[0][1])) - print("\n") - - elif cmd[0] == 'add': - p = int(cmd[1]) - l = int(cmd[2]) - heappush(maxProb, (-l, -p)) - heappush(minProb, (l, p)) - - elif cmd[0] == 'solved': - p = int(cmd[1]) - solvMaxProb.add(p) - solvMinProb.add(p) \ No newline at end of file diff --git "a/week1/datastructure/\353\254\270\354\240\234_\354\266\224\354\262\234_\354\213\234\354\212\244\355\205\234_Version_1/ss721229.py" "b/week1/datastructure/\353\254\270\354\240\234_\354\266\224\354\262\234_\354\213\234\354\212\244\355\205\234_Version_1/ss721229.py" deleted file mode 100644 index 39c7f60a..00000000 --- "a/week1/datastructure/\353\254\270\354\240\234_\354\266\224\354\262\234_\354\213\234\354\212\244\355\205\234_Version_1/ss721229.py" +++ /dev/null @@ -1,43 +0,0 @@ -import sys -from heapq import heappush, heappop - -input = sys.stdin.readline - -N = int(input()) -min_heap, max_heap = [], [] -solved_prm_max, solved_prm_min = set(), set() - -for i in range(N): - P, L = map(int, input().split()) - heappush(min_heap, (L, P)) - heappush(max_heap, (-L, -P)) - -M = int(input()) -for i in range(M): - cmd = list(input().split()) - if cmd[0] == 'add': - P, L = int(cmd[1]), int(cmd[2]) - heappush(min_heap, (L, P)) - heappush(max_heap, (-L, -P)) - elif cmd[0] == 'recommend': - if int(cmd[1]) == 1: - # 가장 어려운 문제 (문제 번호가 가장 큰 것) - while True: - if -max_heap[0][1] in solved_prm_max: - solved_prm_max.remove(-max_heap[0][1]) - heappop(max_heap) - else: - break - print(-max_heap[0][1]) - elif int(cmd[1]) == -1: - # 가장 쉬운 문제 (문제 번호가 가장 작은 것) - while True: - if min_heap[0][1] in solved_prm_min: - solved_prm_min.remove(min_heap[0][1]) - heappop(min_heap) - else: - break - print(min_heap[0][1]) - elif cmd[0] == 'solved': - solved_prm_max.add(int(cmd[1])) - solved_prm_min.add(int(cmd[1])) \ No newline at end of file diff --git "a/week1/datastructure/\354\212\244\355\203\235_\354\210\230\354\227\264/applied7076.py" "b/week1/datastructure/\354\212\244\355\203\235_\354\210\230\354\227\264/applied7076.py" deleted file mode 100644 index b8bc1331..00000000 --- "a/week1/datastructure/\354\212\244\355\203\235_\354\210\230\354\227\264/applied7076.py" +++ /dev/null @@ -1,20 +0,0 @@ -from collections import deque - -if __name__ == "__main__": - n = int(input()) - result = deque([int(input()) for _ in range(n)]) - # print(result) - - stack = deque() - answer = [] - - for i in range(1, n+1): - stack.append(i) - answer.append('+') - - while stack and stack[-1] == result[0]: - stack.pop() - result.popleft() - answer.append('-') - - print('NO' if stack else '\n'.join(answer)) \ No newline at end of file diff --git "a/week1/datastructure/\354\212\244\355\203\235_\354\210\230\354\227\264/ss721229.py" "b/week1/datastructure/\354\212\244\355\203\235_\354\210\230\354\227\264/ss721229.py" deleted file mode 100644 index 425db1c6..00000000 --- "a/week1/datastructure/\354\212\244\355\203\235_\354\210\230\354\227\264/ss721229.py" +++ /dev/null @@ -1,34 +0,0 @@ -import sys -input = sys.stdin.readline - -N = int(input()) - -stack = list() -result = list() -append_cnt = 1 -flag = 0 - -for i in range(N): - num = int(input()) - - if stack and stack[-1] == num: - stack.pop() - result.append('-') - else: - while not flag: - stack.append(append_cnt) - append_cnt += 1 - result.append('+') - - if stack[-1] == num: - stack.pop() - result.append('-') - break - elif append_cnt > N + 1: - flag = 1 - break -if not flag: - for x in result: - print(x) -else: - print('NO') \ No newline at end of file diff --git "a/week1/datastructure/\354\265\234\353\214\200\355\236\231/sehxxnee/heap.py" "b/week1/datastructure/\354\265\234\353\214\200\355\236\231/sehxxnee/heap.py" index e9a682a2..92cb5d9f 100644 --- "a/week1/datastructure/\354\265\234\353\214\200\355\236\231/sehxxnee/heap.py" +++ "b/week1/datastructure/\354\265\234\353\214\200\355\236\231/sehxxnee/heap.py" @@ -3,6 +3,8 @@ N=int(sys.stdin.readline().strip()) + + heap=[] for i in range(N): diff --git "a/week2/dynamic_programming/\353\217\214\352\262\214\354\236\204/sehxxnee/rock.py" "b/week2/dynamic_programming/\353\217\214\352\262\214\354\236\204/sehxxnee/rock.py" new file mode 100644 index 00000000..c49df8ea --- /dev/null +++ "b/week2/dynamic_programming/\353\217\214\352\262\214\354\236\204/sehxxnee/rock.py" @@ -0,0 +1,12 @@ +import sys + +N=int(sys.stdin.readline().strip()) + + +if (N%2==0): + print("CY") + +else: + print("SK") + +#맞긴했는데... 다이나믹으로 풀어야할듯;; \ No newline at end of file diff --git "a/week2/dynamic_programming/\354\204\240\354\210\230\352\263\274\353\252\251/sehxxnee/Prerequisite.py" "b/week2/dynamic_programming/\354\204\240\354\210\230\352\263\274\353\252\251/sehxxnee/Prerequisite.py" new file mode 100644 index 00000000..2c31583e --- /dev/null +++ "b/week2/dynamic_programming/\354\204\240\354\210\230\352\263\274\353\252\251/sehxxnee/Prerequisite.py" @@ -0,0 +1,31 @@ +import sys +from collections import deque + +# n이 과목의 수고 m이 선수 조건의 수 +N,M=map(int,sys.stdin.readline().strip().split()) +table=[[] for _ in range(N+1)] +res= [0]*(N+1) +pre = [0]* (N+1) + + + +for _ in range (M): + #A가 B의 선수과목 + A,B=map(int,sys.stdin.readline().strip().split()) + table[A].append(B) + pre[B]+=1 + +queue=deque() +for i in range(1, N+1): + if pre[i]==0: + queue.append([i,1]) + +while queue: + node, cnt=queue.popleft() + res[node]=cnt + for i in table[node]: + pre[i]-=1 + if pre[i]==0: + queue.append([i, cnt+1]) + +print(*res[1:]) diff --git "a/week2/dynamic_programming/\355\225\251\353\266\204\355\225\264/sehxxnee/partition.py" "b/week2/dynamic_programming/\355\225\251\353\266\204\355\225\264/sehxxnee/partition.py" new file mode 100644 index 00000000..34c1aee0 --- /dev/null +++ "b/week2/dynamic_programming/\355\225\251\353\266\204\355\225\264/sehxxnee/partition.py" @@ -0,0 +1,25 @@ +#DP 문제-> 이전에 계산한 값을 저장해놓고 다시 계산하지 않도록 하는 기법 +# -> 점화식을 구해야 한다. +#dp[k][n] = dp[k-1][0] + dp[k-1][1] + ... + dp[k-1][n] + + +import sys + +X = 1000000000 + +N,K = map(int,sys.stdin.readline().strip().split()) + +dp = [[0] * (N + 1) for _ in range(K + 1)] + +for j in range(N + 1): + dp[1][j] = 1 + +for i in range(2, K + 1): + for j in range(N + 1): + if j == 0: + dp[i][j] = 1 + else: + dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % X + + +print(dp[K][N]) \ No newline at end of file diff --git a/week3/backtracking/sehxxnee/Blackjack.py b/week3/backtracking/sehxxnee/Blackjack.py new file mode 100644 index 00000000..14b23eb7 --- /dev/null +++ b/week3/backtracking/sehxxnee/Blackjack.py @@ -0,0 +1,14 @@ + +N, M = map(int, input().split()) +cards = list(map(int, input().split())) + +max_sum = 0 + +for i in range(N): + for j in range(i + 1, N): + for k in range(j + 1, N): + total = cards[i] + cards[j] + cards[k] + if total <= M: + max_sum = max(max_sum, total) + +print(max_sum) \ No newline at end of file