Skip to content

Instantly share code, notes, and snippets.

@inspirit941
Created December 28, 2019 11:39
Show Gist options
  • Save inspirit941/8fbc13a54ab3685cdaf9d1807be78696 to your computer and use it in GitHub Desktop.
Save inspirit941/8fbc13a54ab3685cdaf9d1807be78696 to your computer and use it in GitHub Desktop.
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