Skip to content

Commit

Permalink
알고리즘
Browse files Browse the repository at this point in the history
  • Loading branch information
sunyeongchoi committed Feb 26, 2021
1 parent ecdf8f8 commit acc1b59
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 7 deletions.
19 changes: 19 additions & 0 deletions argorithm/14494.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
d = [[-1]*(m+1) for _ in range(n+1)]

# n, m에서 왼쪽, 왼쪽위, 위 방향으로 이동하면서 1, 1에 도착했을때의 개수를 더한다.
def dp(n, m):
if n==0 or m==0:
return 0
if n==1 and m==1:
return 1
if d[n][m]!=-1:
return d[n][m]
result = (dp(n,m-1)+dp(n-1,m)+dp(n-1,m-1))%1000000007
d[n][m] = result
return result

print(dp(n, m)%1000000007)
Empty file added argorithm/1967.py
Empty file.
29 changes: 24 additions & 5 deletions argorithm/1991.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
n = int(input())

class Node(object):
def __init__(self, data):
def __init__(self, data, left, right):
self.data = data
self.left = left
self.right = right

tree = {}
for _ in range(n):
node, left, right = input().strip().split()
tmp = Node(data=node)
tmp.left = left
tmp.right = right
tmp = Node(data=node, left=left, right=right)
tree[node] = tmp

result1 = []
Expand All @@ -27,4 +25,25 @@ def pre_order(node):

result2 = []
def in_order(node):
tmp = tree
tmp = tree[node]
if tmp.left!='.':
in_order(tmp.left)
result2.append(node)
if tmp.right!='.':
in_order(tmp.right)

result3 = []
def post_order(node):
tmp = tree[node]
if tmp.left!='.':
post_order(tmp.left)
if tmp.right!='.':
post_order(tmp.right)
result3.append(node)

pre_order('A')
print(''.join(result1))
in_order('A')
print(''.join(result2))
post_order('A')
print(''.join(result3))
19 changes: 19 additions & 0 deletions argorithm/better_spicy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import heapq

def solution(scoville, K):
heap = []
for num in scoville:
heapq.heappush(heap, num)

answer = 0
while heap[0] < K:
answer += 1
try:
heapq.heappush(heap, heapq.heappop(heap)+(heapq.heappop(heap)*2))
except IndexError:
return -1
return answer

if __name__ == '__main__':
real_answer = solution([1, 2, 3, 9, 10, 12], 7)
print(real_answer)
13 changes: 13 additions & 0 deletions argorithm/nf_test1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def solution(A):
answer = []
SA = set(A)
for i in SA:
cnt = 0
for j in A:
cnt += abs(i-j)
answer.append(cnt)
return min(answer)

if __name__ == '__main__':
real_answer = solution([3, 2, 1, 1, 2, 3, 1])
print(real_answer)
16 changes: 16 additions & 0 deletions argorithm/nf_test2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def solution(A, B):
temp = []
if len(A)<len(B): temp = B; B = A; A = temp
A.sort()
B.sort()
i = 0
for a in A:
if i < len(B) - 1 and B[i] < a:
i += 1
if a == B[i]:
return a
return -1

if __name__ == '__main__':
real_answer = solution([1,3,2,5],[4,4,4,4,4,5])
print(real_answer)
15 changes: 15 additions & 0 deletions argorithm/nf_test3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def solution(A):
answer = []
sumval=0
for i in A:
if i<0:
answer.append(sumval)
sumval=0
else:
sumval+=i
answer.append(sumval)
return max(answer)

if __name__ == '__main__':
real_answer = solution([-8,3,0,5,-3,12])
print(real_answer)
1 change: 0 additions & 1 deletion argorithm/test1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
def solution(s1, s2):
answer = set()
min_val = min(len(s1), len(s2))
result1, result2 = '', ''
for i in range(min_val):
if s1[-i:] == s2[:i]:
answer.add(s1+s2[i:])
Expand Down
4 changes: 3 additions & 1 deletion argorithm/test3.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ def solution(grade):
if namogi!=0:
# 3으로 나누어 떨어지는지 확인
if namogi%3==0:

return namogi//3 + moc
else:

# 3로 나눌 경우
grade//3

Expand Down

0 comments on commit acc1b59

Please sign in to comment.