uva 10827

来源:互联网 发布:java方法重写 编辑:程序博客网 时间:2024/04/29 04:05

与108类似 多加了两层循环 水过

#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>#define maxn 110using namespace std;int a[maxn][maxn];int b[maxn];int main(){    int t;    scanf("%d",&t);    while(t--)    {        int n;        scanf("%d",&n);        {            for(int i = 0; i < n; i++)                for(int j = 0; j < n; j++)                {                    scanf("%d",&a[i][j]);                }            int _max = a[0][0];            for(int qq = 0; qq < n; qq++)            {                for(int i = 0; i < n; i++)                {                    memset(b, 0, sizeof(b));                    for(int j = i; j <= i+qq; j++)                    {                        for(int d = 0; d < n; d++)                        {                            b[d] += a[j%n][d];                        }                    }                    for(int pp = 0; pp < n; pp++)                    {                        int sum = 0;                        for(int p = 0; p < n; p++)                        {                            sum += b[(p+pp)%n];                            if(sum > _max)                            {                                _max = sum;                            }                            if(sum < 0)                            {                                sum = 0;                            }                        }                    }                }            }            printf("%d\n",_max);        }    }    return 0;}


原创粉丝点击