diff --git a/suhyun113/DP/4-suhyun113.py b/suhyun113/DP/4-suhyun113.py new file mode 100644 index 0000000..183d20f --- /dev/null +++ b/suhyun113/DP/4-suhyun113.py @@ -0,0 +1,9 @@ +memo = [0, 1] + +n = int(input()) +def fibo(n): + if n >= 2 and n >= len(memo): + memo.append(fibo(n-1)+fibo(n-2)) + return memo[n] + +print(fibo(n)) \ No newline at end of file diff --git a/suhyun113/README.md b/suhyun113/README.md index b25f4a7..c74169e 100644 --- a/suhyun113/README.md +++ b/suhyun113/README.md @@ -4,4 +4,7 @@ |:----:|:---------:|:----:|:-----:|:----:| | 1차시 | 2024.03.25 | 그리디 | [체육복](https://school.programmers.co.kr/learn/courses/30/lessons/42862) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/2) | | 2차시 | 2024.03.29 | 수학 | [소수 & 팰린드롬](https://www.acmicpc.net/problem/1747) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/9) | -| 3차시 | 2024.04.02 | 그리디 | [거스름돈](https://www.acmicpc.net/problem/14916) | [#12](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/12) | \ No newline at end of file +| 3차시 | 2024.04.02 | 그리디 | [거스름돈](https://www.acmicpc.net/problem/14916) | [#12](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/12) | +| 4차시 | 2024.04.06 | DP | [피보나치 수 5](https://www.acmicpc.net/problem/10870) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/16) | +| 5차시 | 2024.04.10 | 스택 | [크레인 인형 뽑기 게임](https://school.programmers.co.kr/learn/courses/30/lessons/64061) | [#19](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/19) | +| 6차시 | 2024.04.14 | 스택 | [컨트롤 제트](https://school.programmers.co.kr/learn/courses/30/lessons/120853) | [#21](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/21) | \ No newline at end of file diff --git "a/suhyun113/\354\212\244\355\203\235/5-suhyun113.py" "b/suhyun113/\354\212\244\355\203\235/5-suhyun113.py" new file mode 100644 index 0000000..b07a0f8 --- /dev/null +++ "b/suhyun113/\354\212\244\355\203\235/5-suhyun113.py" @@ -0,0 +1,24 @@ +def solution(board, moves): + answer = 0 + basket = [float("inf")] # board배열에서 뽑은 인형들을 넣는 바구니 + + N = len(board) # board 2차원 배열은 N*N이므로, board의 행 또는 열의 길이를 N으로 받음. + + # moves 1차원 배열에 있는 요소에 따라 어떤 열의 인형을 뽑을 지 정함. + for move in moves: #[1 5 3 5 1 2 1 4] + move -= 1 # 1번째가 실제로 board배열에서는 0번째 이므로, 각 요소마다 1씩 빼줌. + doll = 0 # 인형이 비어있다고 가정 -> 0으로 초기화 + + for i in range(N): + if board[i][move] != 0: # 열은 move로 정해져 있고, 행이 i로 계속 변함. + doll = board[i][move] # 0이 아니라면, 인형이 있는 것이므로, 인형의 값을 변경 + board[i][move] = 0 + break + + if doll != 0: # 인형이 비어있지 않아서 doll에 새로운 인형의 값이 들어갔을 때, + if basket[-1] == doll: # 바구니 가장 위에 담긴 인형과 새로 뽑은 인형이 같다면 + basket.pop() # 바구니 가장 위의 인형 제거 + answer += 2 # 같은 인형이 바구니에 담겼으므로, 2개의 인형이 터짐 + else: + basket.append(doll) # 바구니의 가장 위의 인형과 같은 인형이 아니라면, doll을 새로 바구니에 추가하기 + return answer \ No newline at end of file diff --git "a/suhyun113/\354\212\244\355\203\235/6-suhyun113.py" "b/suhyun113/\354\212\244\355\203\235/6-suhyun113.py" new file mode 100644 index 0000000..6018767 --- /dev/null +++ "b/suhyun113/\354\212\244\355\203\235/6-suhyun113.py" @@ -0,0 +1,20 @@ +def solution(s): + answer = 0 + + stack = [float("inf")] + + # 문자열을 공백 기준으로 나누어 리스트에 저장 + s_list = s.split() + + for i in s_list: # i는 s_list의 인덱스가 아닌 값 + if i != 'Z': + stack.append(i) + else: + stack.pop() # stack의 가장 위의 값 빼기 + stack.pop(0) + + # 문자를 정수로 변환하기 + for i in stack: + n = int(i) + answer += n + return answer \ No newline at end of file