1449.txt
来自「自己AC的zju_acm上的若干个题目,都是自己辛辛苦苦AC的。」· 文本 代码 · 共 73 行
TXT
73 行
#include<iostream.h>
#include<string.h>
long maxsum1(long s[101],long n)
{
long sum=0;
long temp=0;
long i;
long row=n;
for(i=1;i<=row;i++)
{if(temp>0) temp+=s[i];
else temp=s[i];
if(temp>sum) sum=temp;
}
return sum;
}
long maxsum2(long b[][21],long n)
{long i,j,k,sum,max;
long s[101];
sum=0;
memset(s,0,sizeof(s));
for(i=1;i<=n;i++)
{for(k=1;k<=n;k++) s[k]=b[i][k];
max=maxsum1(s,n);
if(max>sum) sum=max;
for(j=i+1;j<=n;j++)
{
for(k=1;k<=n;k++)
s[k]+=b[j][k];
max=maxsum1(s,n);
if(max>sum) sum=max;
}
if(j-1==1) sum=s[1];
}
return sum;
}
int main()
{
long i,j,k,l,max,sum,n;long a[21][21][21]; long b[21][21];
while(1)
{
cin>>n;
if(!n) break;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
for(k=1;k<=n;k++)
cin>>a[i][j][k];
sum=0;
if(n==1) cout<<a[1][1][1]<<endl;
else
{
memset(b,0,sizeof(0));
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
for(k=1;k<=n;k++)
b[j][k]=0;
for(l=i;l<=n;l++)
{for(j=1;j<=n;j++)
for(k=1;k<=n;k++)
b[j][k]+=a[l][j][k];
max=maxsum2(b,n);
if(max>sum) sum=max;
}
}
cout<<sum<<endl;
}
}
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?