[USACO1.5][IOI1994]数字三角形 Number Triangles - 洛谷
"""
P1216 [USACO1.5][IOI1994]数字三角形 Number Triangles(python3实现)
https://www.luogu.com.cn/problem/P1216
"""
a=[[0 for i in range(1010)] for j in range(1010)]
n=int( input() )
for i in range(n):
a[i] = input().split(" ") #输入二维数组,同行数字用空格分隔,不同行则用回车换行
a[i] = [int(j) for j in a[i]] #将数组中的每一行转换成整型
i=n-2
while i>=0:
for j in range(i+1):
a[i][j]+=max(a[i+1][j],a[i+1][j+1])
i-=1
print(a[0][0])
参考:
Python输入数组(一维数组、二维数组)
https://blog.csdn.net/weixin_30509393/article/details/96951174
python输入定长数组和输入不定长数组
https://blog.csdn.net/Cai_Xu_Kun/article/details/110453925