码迷,mamicode.com
首页 > 其他好文 > 详细

【矩阵压缩】 poj 1050

时间:2014-10-10 00:13:21      阅读:342      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   for   sp   div   

题意:给一个矩阵,里面有正负数,求子矩阵和的最大值

 

#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <memory.h>
using namespace std;
int s[105][105],dp[105],n,temp[105];
int main()
{
    // freopen("in.txt","r",stdin);
    cin>>n;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            cin>>s[i][j];
    int maxx = 0;
    for (int i=1;i<=n;i++) //start from line i
    {
        memset(temp,0,sizeof(temp));
        for (int j=i;j<=n;j++) //end at line j
        {
            for (int k=1;k<=n;k++)
            {
                temp[k]+=s[j][k];
                if (temp[k]+dp[k-1]>0)
                dp[k]=temp[k]+dp[k-1];
                else
                dp[k]=0;
                if (maxx<dp[k])
                    maxx =dp[k];
            }
        }
     }
    cout << maxx << endl;
}

 

【矩阵压缩】 poj 1050

标签:style   blog   color   io   os   ar   for   sp   div   

原文地址:http://www.cnblogs.com/balfish/p/4014582.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!