Skip to content

Instantly share code, notes, and snippets.

@zsrinivas
Created May 3, 2015 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zsrinivas/13964f5900357bcd19b3 to your computer and use it in GitHub Desktop.
Save zsrinivas/13964f5900357bcd19b3 to your computer and use it in GitHub Desktop.
spoj: classical ⇝ wpc4f ⇝ Through the troops
#!/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