Created
May 3, 2015 10:01
-
-
Save zsrinivas/13964f5900357bcd19b3 to your computer and use it in GitHub Desktop.
spoj: classical ⇝ wpc4f ⇝ Through the troops
This file contains 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
#!/usr/bin/python | |
# -*- encoding: utf-8 -*- | |
# pylint: disable=invalid-name,missing-docstring,bad-builtin,star-args | |
from sys import stdin | |
def main(): | |
dstream = iter(map(int, stdin.read().split())) | |
for _ in xrange(next(dstream)): | |
mat = [[next(dstream), next(dstream), next(dstream)] for _ in xrange(next(dstream))] | |
for x in xrange(1, len(mat)): | |
for y in xrange(3): | |
mat[x][y] += min(mat[x - 1][:y] + mat[x - 1][y + 1:]) | |
print min(mat[-1]) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment