题解 | #最大子矩阵#
最大子矩阵
https://www.nowcoder.com/practice/a5a0b05f0505406ca837a3a76a5419b3
def max_sum(num: list):#本质还是最大连续子序列 dp = [-99 for i in range(len(num) + 1)] dp[0] = num[0] for i in range(len(num)): dp[i] = max(num[i], dp[i - 1] + num[i]) return max(dp) n = int(input()) mat = [[] for i in range(n)] for i in range(n): # 矩阵的输入 mat[i] = list(map(int, input().split(" "))) ans = [0 for i in range(n)] res = [] for i in range(n): ans = [0 for i in range(n)] for j in range(i, n): for k in range(n): ans[k] = ans[k] + mat[j][k] res.append(max_sum(ans)) print(max(res))