求助 P1719,找不到哪里有问题

P1719 最大加权矩形

wmylhr @ 2023-04-23 20:05:13

n=int(input())
ans=-100000
s=[[0]*(n+1)]  #s储存了矩阵
for i in range(n):
    s.append(([0]+list(map(int,input().split()))))
for i in range(1,n+1):
    dp=[0 for _ in range(n+2)]
    for j in range(i,n+1):

        for k in range(1,n+1):
            dp[k]+=s[j][k]
        sum1=dp[1]

        ans=max(ans,sum1)
        for h in range(2,n+1):
            if sum1+dp[h]<dp[h+1]:
                sum1=dp[h+1]
            else:
                sum1+=dp[h]
            ans=max(ans,sum1)

print(ans)

|