1import copy, sys 2 3N, M = map(int, input().split()) 4L = [list(map(int, input().split())) for _ in range(N)] 5cctv = [] 6direction = [[[(0, 1)], [(0, -1)], [(1, 0)], [(-1, 0)]], 7[[(-1, 0), (1, 0)], [(0, -1), (0, 1)]], 8[[(-1, 0), (0, -1)], [(0, -1), (1, 0)], [(1, 0), (0, 1)], [(0, 1), (-1, 0)]], 9[[(-1, 0), (0, -1), (1, 0)], [(0, -1), (1, 0), (0, 1)], [(1, 0), (0, 1), (-1, 0)], [(0, 1), (-1, 0), (0, -1)]], 10[[(-1, 0), (0, -1), (1, 0), (0, 1)]]] 11res = sys.
์ ๊ทผ์ด ์ด๋ ค์ ์ธํฐ๋ท์ ์ฐธ๊ณ ํ๋ค. ์ฝ๋๋ ๋ณด์ง ์์๋ค. ์์ ๊ธธ์ด๊ฐ i์ด๋ฉด์ ๋ง์ง๋ง ์ซ์๊ฐ j์ธ ๊ณ๋จ ์์ ๊ฐ์๋ฅผ ์ ์ฅํ๋ ๊ฒ์ด ํต์ฌ์ด๋ค. ์ ํ์์ L[i][j] = L[i-1][j-1]+L[i-1][j+1] ์ด๋ค. 1N = int(input()) 2L = [[0]*12 for _ in range(100)] 3L[0] = [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0] 4 5for i in range(1, N): 6 for j in range(1, 11): 7 L[i][j] = L[i-1][j-1]+L[i-1][j+1] 8 9print (sum(L[N-1])%1000000000)
1N = int(input()) 2L = [list(map(int, input().split())) for _ in range(N)] 3dp1 = [L[0][i] for i in range(3)] 4dp2 = [L[0][i] for i in range(3)] 5 6for i in range(1, N): 7tmp1 = [0]*3 8tmp2 = [0]*3 9for j in range(3): 10 11 if j == 0: 12 tmp1[0] = L[i][j] + max(dp1[0], dp1[1]) 13 tmp2[0] = L[i][j] + min(dp2[0], dp2[1]) 14 elif j == 1: 15 tmp1[1] = L[i][j] + max(dp1[0], dp1[1], dp1[2]) 16 tmp2[1] = L[i][j] + min(dp2[0], dp2[1], dp2[2]) 17 else: 18 tmp1[2] = L[i][j] + max(dp1[1], dp1[2]) 19 tmp2[2] = L[i][j] + min(dp2[1], dp2[2]) 20 dp1 = [i for i in tmp1] 21 dp2 = [i for i in tmp2] 22 23print (max(dp1), min(dp2)) Memoization๊ณผ์ ์ด ๋ค๋ฅธ memoization ๋ณ์์ ๋ํด ์ข
์์ ์ด๋ผ๋ฉด ์๋ชป๋ ๊ฒฐ๊ณผ๋ฅผ ์ด๋ํ๋ค ์ ์ฝ๋์์๋ ์ด๋ฅผ ๋ฐฉ์งํ๊ธฐ ์ํด tmp1, tmp2 ๋ณ์๋ฅผ ์ฌ์ฉํ๋ค ๊น์ด ์๊ฐํ์ง ์๊ณ ์ฌ๋ฌ ๋ฒ ์ ์ถํด์ WA๊ฐ์๊ฐ ์กฐ๊ธ ๋ง๋ค;;