Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- import numpy as np
- n = int(input("Введите размерность матрицы: "))
- matrix = np.array([[randint(-30, 30) for x in range(n)] for y in range(n)])
- print(matrix)
- start_comb = []
- for i in range(1, n):
- init_comb = []
- start = 0
- for j in range(i, n):
- init_comb.append((start, j))
- start += 1
- start_comb.append(init_comb.copy())
- starting_comb = [[x[::-1] for x in y] for y in start_comb][::-1] + start_comb
- # print(starting_comb)
- sums = []
- for combs in starting_comb:
- sum = 0
- for comb in combs:
- sum += matrix[comb[0]][comb[1]]
- sums.append(sum)
- print(sums)
- print(max(sums))
Advertisement
Add Comment
Please, Sign In to add comment