https://www.acmicpc.net/problem/1932
오답.
동적 계획법 문제였다.
어제 했던 RGB문제랑 풀이는 똑같았다.
근데 테스트할 때 썼던 5*5 배열의 캐시를 그대로 제출해서 한번 틀렸다😥
정신 좀 차리자.
import sys
sys.setrecursionlimit(10**6)
n = int(sys.stdin.readline())
cache = [[-1 for x in range(n)] for y in range(n)]
num = []
def p(y,x) :
if y == n-1 :
return num[y][x]
if cache[y][x] != -1 :
return cache[y][x]
val = num[y][x] + max(p(y+1,x),p(y+1,x+1))
cache[y][x] = val
return val
for i in range(n) :
num.append(list(map(int,sys.stdin.readline().rstrip().split())))
print(p(0,0))