전체 글
(CodeUp) 코드업 1930 - Python - SuperSum
dic = {} def superSum(k, n): if k == 0: return n find = str(k) + '-' + str(n) if find in dic: return dic[find] sum = 0 for i in range(1, n+1): sum += superSum(k-1, i) dic[find] = sum return dic[find] while(True): try: k, n = input().split(' ') k = int(k) n = int(n) print(superSum(k, n)) except EOFError: break
(Baekjoon) 백준 9095 - Python - 1, 2, 3 더하기
dic = {0:0, 1:1} def recursion(n): if n in dic: return dic[n] if n < 1: return 0 dic[n] = recursion(n-1) + recursion(n-2) + recursion(n-3) return dic[n] T = int(input()) arr = list() for i in range(T): arr.append(int(input())) for i in arr: print(recursion(i+1))
(Baekjoon) 백준 2447 - Python - 별 찍기 - 10
def recursion(n,k): global arr if n < 3: return if n == 3: arr[1][1] = ' ' return for i in range(k): for j in range(k): if(int(n/3)
(CodeUp) 코드업 1915 - Python - (재귀함수) 피보나치 수열
def fibo(n): if n == 0: return 0 elif n == 1 or n == 2: return 1 else: return fibo(n-1) + fibo(n-2) n = int(input()) result = fibo(n) print(result)
(CodeUp) 코드업 1954 - Python - (재귀함수)삼각형 출력하기 2
def recursion(n): if n < 2: return '*' else: return '*' * n + '\n' + recursion(n-1) n = int(input()) result = recursion(n) print(result)
(CodeUp) 코드업 1917 - Python - (재귀 함수) n의 k승 구하기
def recursion(n, k): if n == 1 or k == 0 : return 1 elif n == -1: if k%2==0: return -n else : return n elif k < 2: return n else: return recursion(n, k-1) * n n, k = input().split(' ') n = int(n) k = int(k) result = recursion(n, k) print(result)
(CodeUp) 코드업 1935 - Python - (재귀함수) LCA
def deep(a, b): if a==b: return a elif a>b: return deep(int(a/2),int(b)) elif a