This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| n = int(input()) | |
| p, d = [0] * (n+1), [0] * (n+1) | |
| p = list(map(int, input().split())) | |
| p.insert(0, 0) | |
| for i in range(1, n+1): | |
| for j in range(1, i+1): | |
| if d[i] < d[i-j] + p[j]: | |
| d[i] = d[i-j] + p[j] | |
| print(d[n]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def f(n): | |
| d = [0] * (n+1) | |
| d[0] = 1 | |
| d[1] = 1 | |
| for i in range(2, n+1): | |
| d[i] = d[i-1] + 2 * d[i-2] | |
| d[i] %= 10007 | |
| return d[n] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def f(n, seq): | |
| print("Simulation %d" % ctn) | |
| cache = [] | |
| for i in seq: | |
| for j in i: | |
| if j is "!": | |
| print(''.join(reversed(cache))) | |
| continue | |
| if j in cache: | |
| cache.pop(cache.index(j)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def f(str): | |
| while "()" in str: | |
| str = str.replace("()", "") | |
| if len(str) >= 1: | |
| print("NO") | |
| else: | |
| print("YES") | |
| for _ in range(int(input())): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Stack: | |
| def __init__(self, length): | |
| self.d = [None] * length | |
| self.top = -1 | |
| def len(self): | |
| return self.top+1 | |
| def append(self, item): | |
| self.top += 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ๊ฐ์ ์ ๋์ค๋, ์๊ฐ์ด๊ณผ๊ฐ ๋ฐ์ํ๋ค. ์์๋ณด๋ ํฌํจ-๋ฐฐ์ ์ ์๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ค๊ณ ํ๋ค. ์ผ๋จ ํจ์ค | |
| def gcd(m: int, n: int): | |
| while n != 0: | |
| t = m % n | |
| m, n = n, t | |
| return abs(m) | |
| def f(a: int, b: int, n: int): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # DP๋ ์กฐํฉ๊ด๋ จ ๋ฌธ์ ์ ์ฌ์ฉ, ์กฐํฉ ๊ด๋ จ ๋ฌธ์ ์ผ ๋ ์ ํ์์ ๋ํ๊ธฐ ์ฌ์ฉ | |
| # ํ์ผ ์กฐํฉ ๋ฌธ์ ์ ๊ฒฝ์ฐ 2x1์ ์ ์ธํ๊ณ ๋๋จธ์ง๋ 2xn์กฐํฉ์์(n > 1) | |
| # ์ฃผ์ด์ง ํ์ผ์ ์กฐํฉํ๋ฉฐ ์ฌ์ฉํ๋ฉด ๋๋ฏ๋ก ๋ํ๊ธฐ ์ฌ์ฉ | |
| # ์ด ๋ฌธ์ ์ ๊ฒฝ์ฐ. | |
| # 1์ผ ๋ (1), 2์ผ ๋ (1, 1), (2) ์ ๊ฐ์ ์กฐํฉ์ฒ๋ผ | |
| # n=2 ์ผ๋ n-3์ ํ ์ ์์, ์ฆ n >= 0 | |
| def f(n): | |
| if n <= 1: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Node: | |
| def __init__(self, data): | |
| self.data = data | |
| self.next = None | |
| class CircularLinkedList: | |
| def __init__(self): | |
| self.tail = None | |
| self.head = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Node: | |
| def __init__(self, data): | |
| self.data = data | |
| self.next = None | |
| class LinkedList: | |
| def __init__(self): | |
| self.tail = None | |
| self.head = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ๋ฌธ์ ์ ์กฐ๊ฑด | |
| 2 x 1(์ธ๋ก) ํ์ผ๊ณผ | |
| 1 x 2(๊ฐ๋ก) ํ์ผ์ ์ฌ์ฉํด | |
| 2 x n ํ์ผ์ ์ฑ์๋ผ | |
| 1 x 2 ๋ฅผ ์ฌ์ฉ์ 1 x 2๋ฅผ ํ ๋ฒ๋ ์ฌ์ฉํด์ผํ๋ฏ๋ก 2๊ฐ๋ฅผ 1๊ฐ๋ก ์ทจ๊ธ | |
| ํ์ผ์ ํฌ๊ธฐ๊ฐ n ์ผ ๋ ์ธ๋ก ํ์ผ์ n์นธ์์ 1์นธ์ ์ฐจ์ง -> n-1 | |
| n-1 1 | |
| --------- |