python版本来了,递归
import sys n = sys.stdin.readline().strip() m = [] line_num = 0 for line in sys.stdin.readlines(): #temp = sys.stdin.readline().strip().split(' ') temp = line.strip().split(' ') m.append(temp) dp = m if n < 2: print(int(dp[0][0])) else: for i in range(int(n)-2,-1,-1): for j in range(i,-1,-1): dp[i][j] = max(int(dp[i+1][j]),int(dp[i+1][j+1])) + int(dp[i][j]) print(int(dp[0][0]))唉,检查半天readline出错,用不惯啊用不惯