| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
这个,,在杭电上也能A(考虑了全为负的情况)
#include<iostream>
using namespace std;
int main()
{
int A[200][200]={0};
int N,i,j,k;
while(~scanf("%d",&N))
{
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
cin>>A[i][j];
}
}
int B[200][200]={0};
int max=A[0][0];
int s=0;
for(j=0;j<N;j++)
{
for(i=0;i<N;i++)
{
B[i][j]=s+A[i][j];
s=B[i][j];
}
s=0;
}
s=0;
for(k=0;k<N;k++)
{
for(i=k;i<N;i++)
{
for(j=0;j<N;j++)
{
if(i==k)
s+=A[i][j];
else
{
if(k==0)
s+=B[i][j];
else
{
if(k==0)
s+=B[i][j];
else
s+=B[i][j]-B[k-1][j];
}
}
if(s>max && s!=0)
max=s;
if(s<0)
s=0;
}
s=0;
}
}
cout<<max<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator