Problem description
Yang Hui triangle is also called Pascal triangle , It's the first i+1 Line is (a+b)i The coefficients of the expansion of .
One of its important properties is : Each number in a triangle is the sum of the numbers on its shoulders .
The first part of Yang Hui's triangle is given below 4 That's ok :
1
1 1
1 2 1
1 3 3 1
give n, Output its front n That's ok .
Input format
The input contains a number n.
Output format
Output the front of Yang Hui triangle n That's ok . Each line starts with the first number of the line and outputs in turn , Use a space in the middle . Please don't output extra spaces in the front .
The sample input
4
Sample output
1
1 1
1 2 1
1 3 3 1
Data scale and agreement
1 <= n <= 34.
Ideas :
One 、 Each number is equal to the sum of the two numbers on the previous line . Use this property to write the whole Yanghui triangle . That is to say n+1 OK, No i The number is equal to the n OK, No i-1 Number and number i Sum of numbers , This is also one of the properties of combinatorial numbers . namely C(n+1,i)=C(n,i)+C(n,i-1).
Two 、 The first n Yes m The number can be expressed as C(n-1,m-1), From n-1 Among the different elements m-1 Number of combinations of elements .
n = int(input())
N = [1]
for m in range(n):
for i in range(len(N)):
if i == len(N) - 1:
print(N[i])
else:
print(N[i],end=' ')
N.append(0)
N = [N[k] + N[k-1] for k in range(i+2)]