POJ-1050 To the Max Posted on 2019-03-21 | Edited on 2019-04-01 | In poj | Views: 题意求最大子矩阵和。 题解枚举列区间,将该区间的值压缩到一起,转化成求一维最大字段。 代码1234567891011121314151617181920212223242526272829303132333435363738394041424344#include <cstring>#include <ctime>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <set>#include <string>#include <vector>#define ll long long#define inf 0x3f3f3f3f#define for0(i, n) for (int i = 0; i < n; i++)#define for1(i, n) for (int i = 1; i <= n; i++)#define forl(i, l, r) for (int i = l; i <= r; i++)#define forn(i, n) for (int i = n; i >= 0; i--)#define mem0(a) memset(a, 0, sizeof(a))#define meminf(a) memset(a, inf, sizeof(a))using namespace std;int main() { ios::sync_with_stdio(false); int n, a[101][101],b[101][101]; cin >> n; mem0(b); for0(i, n) { for0(j, n){ cin>>a[i][j]; b[i][j+1]=b[i][j]+a[i][j]; } } int ans=0; for0(i, n) forl(j, i+1, n){ int tmp=0; for0(k, n){ tmp+=b[k][j]-b[k][i]; if (tmp<0) { tmp=0; }else if(tmp>ans){ ans=tmp; } } } cout<<ans<<endl;}