Takes list of strings `matrix_str` to parse the matrix and calculates the max sum. >>> solution(["1 2", "3 4"]) 5 >>> solution(MATRIX_1) 3315
(matrix_str: list[str] = MATRIX_2)
| 93 | |
| 94 | |
| 95 | def solution(matrix_str: list[str] = MATRIX_2) -> int: |
| 96 | """ |
| 97 | Takes list of strings `matrix_str` to parse the matrix and calculates the max sum. |
| 98 | |
| 99 | >>> solution(["1 2", "3 4"]) |
| 100 | 5 |
| 101 | >>> solution(MATRIX_1) |
| 102 | 3315 |
| 103 | """ |
| 104 | |
| 105 | n = len(matrix_str) |
| 106 | arr = np.empty(shape=(n, n), dtype=int) |
| 107 | for row, matrix_row_str in enumerate(matrix_str): |
| 108 | matrix_row_list_str = matrix_row_str.split() |
| 109 | for col, elem_str in enumerate(matrix_row_list_str): |
| 110 | arr[row, col] = int(elem_str) |
| 111 | |
| 112 | cache: dict[str, int] = {} |
| 113 | return solve(arr=arr, row=0, cols=set(range(n)), cache=cache) |
| 114 | |
| 115 | |
| 116 | if __name__ == "__main__": |