# Function to demonstrate printing pattern triangle
def triangle(n):
# BEGIN SOLUTION
# number of spaces
k = n - 1
# outer loop to handle number of rows
for i in range(0, n):
# inner loop to handle number spaces
# values changing according to requirement
for j in range(0, k):
print(end=" ")
# decrementing k after each loop
k = k - 1
# inner loop to handle number of columns
# values changing according to outer loop
for j in range(0, i + 1):
# printing stars
print("*", end=" ")
# ending line after each row
print("")
# END SOLUTION
# Driver Code
n = 7
triangle(n)
class Person:
species = 'Human'
def __init__(self, name):
self.name = name
# 实例方法
def say_hello(self):
return f"Hello, my name is {self.name}."
# 类方法
@classmethod
def get_species(cls):
return f"I am a {cls.species}."
# 静态方法
@staticmethod
def general_greeting():
return "Hello, there!"
# 创建实例
person = Person("Alice")
# 调用实例方法
print(person.say_hello()) # 需要实例
# 调用类方法
print(Person.get_species()) # 可以直接通过类调用
print(person.get_species()) # 也可以通过实例调用
# 调用静态方法
print(Person.general_greeting()) # 可以直接通过类调用
print(person.general_greeting()) # 也可以通过实例调用
n = int(input())
a = []
for i in range(n):
a.append(list(map(int,input().split())))
for i in range(1,n):
for j in range(0,i+1):
# 下面的两个都是对在最左和最右侧元素的处理
if j == 0:
a[i][j] += a[i-1][j]
elif i == j:
a[i][j] += a[i-1][j-1]
# 若元素在中间就把两者取大者
else:
a[i][j] += max(a[i-1][j-1],a[i-1][j])
# 不用更新,直接加到最后
print(max(a[n-1]))