Design ideas
And one-dimensional loop array thinking similar, loop n times, each time the number of the first column to the last column, a new two-dimensional array of the same specification to hold the new matrix, the previous write to find two-dimensional array of the largest sub-matrix of the algorithm slightly modified, add a loop to meet the requirements.
SOURCE program code
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace Std;
#define M 4
#define N 4
void Main ()
{
int a[m][n],aa[m][n],i,j,b,c,z;
cout<< "Please enter a range of values:" <<endl;
cin>>b>>c;
cout<< "Generate a two-dimensional array:" <<endl;
Srand (Unsigned (time (0)));
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
A[i][j]=rand ()% (c-b+1) +b;
cout<<a[i][j]<< "";
}
cout<<endl;
}
int sum,s[100],k=0,o=-1000,p=-1000,q=-1000;
for (j=0;j<n;j++)
{
s[j]=0;
}
for (int lun=0;lun<n;lun++)
{
for (int lunm=0;lunm<m;lunm++)
{
for (int lunn=0;lunn<n;lunn++)
{
if (lunn+lun<n)
{
Aa[lunm][lunn]=a[lunm][lunn+lun];
}
Else
AA[LUNM][LUNN]=A[LUNM][LUNN+LUN-N];
}
}
for (int ii=0;ii<m;ii++)
{
while (K+II<M)
{
for (j=0;j<n;j++)
{
S[J]=S[J]+AA[K+II][J];
}
for (i=0;i<n;i++)
{
for (j=i;j<n;j++)
{
sum=0;
for (z=i;z<=j;z++)
{
SUM=SUM+S[Z];
}
if (Sum>o) o=sum;
}
if (o>p)
{
P=o;
}
}
k++;
}
if (P>Q)
{
Q=p;
}
k=0;
for (j=0;j<n;j++)
{
s[j]=0;
}
}
}
cout<< "sub-matrix Maximum value:" <<q<<endl;
}
Run results
Programming summary
It can save a lot of time to modify the code based on the original code, so you should be able to read the code and modify the code skillfully.
Returns the and of the largest sub-matrices in a two-dimensional loop array