uva 108

来源:互联网 发布:网络上lay是什么意思 编辑:程序博客网 时间:2024/04/30 13:52

降维  枚举行累加   然后求单行上最大连续和

#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 n;    while(scanf("%d",&n) == 1)    {        int _max = -100000;        for(int i = 0; i < n; i++)            for(int j = 0; j < n; j++)                scanf("%d",&a[i][j]);        for(int i = 0; i < n; i++)        {            for(int j = i; j < n; j++)            {                memset(b, 0, sizeof(b));                for(int k = i; k <= j; k++)                {                    for(int d = 0; d < n; d++)                    {                        b[d] += a[k][d];                    }                }                int sum = 0;                for(int p = 0; p < n; p++)                {                    sum += b[p];                    if(sum > _max)                    {                        _max = sum;                    }                    if(sum < 0)                    {                        sum = 0;                    }                }            }        }        printf("%d\n",_max);    }    return 0;}


原创粉丝点击