Created
December 28, 2019 11:39
-
-
Save inspirit941/8fbc13a54ab3685cdaf9d1807be78696 to your computer and use it in GitHub Desktop.
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
import sys | |
n = int(sys.stdin.readline()) | |
arr = [] | |
for _ in range(n): | |
arr.append(list(map(int, sys.stdin.readline().split()))) | |
table = [[0 for _ in range(3)] for _ in range(n)] | |
for i in range(n): | |
for j in range(3): | |
if i == 0: | |
table[i][j] = arr[i][j] | |
else: | |
table[i][j] = min(table[i-1][(j+1)%3], table[i-1][(j+2)%3]) + arr[i][j] | |
print(min(table[-1])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment