[Login|Register]
New post

Show post

Search forum

Read post
找不到为啥WA了 [ Topic ] 2015-10-22 14:12:31 simplecherry
#include <stdio.h>
#include <string.h>
#define  MIN -1000000000

long max1(long *m,long n)
{
    long sum=MIN,temp=MIN,i;
    for (i=1;i<=n;++i)
    {
        if (temp>0) temp+=m[i];
        else temp=m[i];
        if (temp>sum) sum=temp;
    }
    return sum;
}

long max2(long m[][21],long n)
{
    long s[21],i,j,k,sum=MIN,temp;
    for (i=1;i<=n;++i)
    {
        memset(s,0,sizeof(s));
        for (j=i;j<=n;++j)
        {
            for (k=1;k<=n;++k)
                s[k]+=m[j][k];
            temp=max1(s,n);
            if (temp>sum) sum=temp;
        }
    }
    return sum;
}

int main()
{
    long m[21][21][21],s[21][21],i,j,k,l,sum=MIN,temp,n;
    while (1)
    {
        scanf("%ld",&n);
        if (!n) return 0;
        for (i=1;i<=n;++i)
            for (j=1;j<=n;++j)
                for (k=1;k<=n;++k)
                    scanf("%ld",&m[i][j][k]);
        
        for (i=1;i<=n;++i)
        {
            memset(s,0,sizeof(s));
            for (j=i;j<=n;++j)
            {
                for (k=1;k<=n;++k)
                    for (l=1;l<=n;++l)
                        s[k][l]+=m[j][k][l];
                temp=max2(s,n);
                if (temp>sum) sum=temp;
            }
        }
        printf("%ld\n",sum);
    }
}
Reply
Title
Message
(64K)
University of Science and Technology of China
Online Judge for ACM/ICPC
Processed in 2.2ms with 2 query(s).