Example: Timus 1146. Maximum Sum
The maximum sub-matrix can be converted to the most problematic sequence, and the oldest sequence can do this:
A[n], the maximum subsequence of A[n] is two possible (1) consecutive to A[i]. (2) starting from a[i]. (If you do not include a[i], it is well before, no tube). You can use this loop to find the maximum number of sub-sequences
int maxl (int n) { int ans=-1e9,s=0; for (int i=1; i<=n;i++) { s=max (s+b[i],b[i]); if (s>ans) { ans=s; } } return ans;}
View Code
Full code
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;intnum[ the][ the];intb[ the];intMaxlintN) { intans=-1e9,s=0; for(intI=1; i<=n;i++) {s=max (s+B[i],b[i]); } returnans;}voidComputeintN) { intans=-1e9; for(intI=1; i<=n;i++) {memset (b,0,sizeof(b)); for(intj=i;j<=n;j++){ for(intk=1; k<=n;k++) {B[k]+=Num[j][k]; } intret=MAXL (n); if(ret>ans) {ans=ret; }}} printf ("%d\n", ans);}intMain () {intN; while(~SCANF ("%d",&N)) { for(intI=1; i<=n;i++){ for(intj=1; j<=n;j++) {scanf ("%d",&Num[i][j]); }} compute (n); } return 0;}View Code
Maximum sub-matrix