Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = 20
- # m will be a 20x20 matrix with zeros
- m = [[0 for _ in range(n)] for __ in range(n)]
- # Initialization
- # Diagwnia stoixeia = 1
- for i in range(n):
- m[i][i] = 1
- '''
- for i in range(n):
- for j in range(i+1, n):
- m[i][j] = 0
- for k in range(i, j):
- m[i][j] += m[i][k] * m[k+1][j]
- if m[i][k] == 0 or m[k+1][j] == 0:
- raise Exception('There is a zero element')
- '''
- # To k "deixnei" tin diagwnio pou eimai
- # 1η διαγώνιος το i πάει από 0 ως και το 5
- # 2η διαγώνιος το ι πάει από 0 ως και το 4
- for diag in range(1, n):
- for i in range(0, n-diag):
- j = i+diag
- m[i][j] = 0
- for k in range(i, j):
- m[i][j] += m[i][k] * m[k + 1][j]
- if m[i][k] == 0 or m[k + 1][j] == 0:
- raise Exception('There is a zero element')
- print(m[0][n-1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement