To The Max (动态规划//最大连续子序列和) 。
Problem DescriptionGiven a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous sub-array of size 1 x 1 or greater located within the whole array. The sum of a rectangle is the sum of all the elements in that rectangle. In this problem the sub-rectangle with the largest sum is referred to as the maximal sub-rectangle.4 0 -2 -7 0 9 2 -6 2 -4 1 -4 1 -1 8 0 -2?
15
降维运算,我们可以先把从i到j行的每一列加起来求最大连续子序列和,然后求出最大值即可(注意多组输入);
#include#include #include using namespace std; typedef long long ll; #define MAXN 1000 const int INF=1<<29; int a[MAXN][MAXN]; int b[1000050]; int main() { int n; while(cin>>n) { for(int i=0;i >a[i][j]; } } int ans=-INF; for(int i=0;i 0) sum+=b[k]; else sum=b[k]; if(sum>ans) ans=sum; } } } cout<<>