iamsuneeth

Untitled

Jul 26th, 2014
219
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. c = int(raw_input())
  2. while c>0:
  3.     n = int(raw_input())
  4.     a =[]
  5.     get=[]
  6.     for i in xrange(n):
  7.         get = map(int,raw_input().split())
  8.         a.append(get)
  9.  
  10.     for i in xrange(1,n):
  11.         for j in xrange(i+1):
  12.             if j==0:
  13.                 a[i][j]+=a[i-1][j]
  14.             elif j==i:
  15.                 a[i][j]+=a[i-1][j-1]
  16.             else:
  17.                 if a[i-1][j-1]>a[i-1][j]:
  18.                     a[i][j]+=a[i-1][j-1]
  19.                 else:
  20.                     a[i][j]+=a[i-1][j]
  21.  
  22.     large = 0
  23.     for l in a[n-1]:
  24.         if l>large:
  25.             large = l
  26.     print large
  27.     c-=1
RAW Paste Data