Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

N^3都能16MS……囧

Posted by speedcell4 at 2012-02-23 12:48:22 on Problem 1050 and last updated at 2012-02-23 12:51:48
#include<iostream>

using namespace std;

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

const int MAXN = 120;
const int  inf = 0x7f7f7f7f;

int n,a[MAXN][MAXN],dp[MAXN];

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=1;n-i>=0;i++)
        {
            for(int j=1;n-j>=0;j++)
            {
                scanf("%d",&a[i][j]);
            }
        }
        int ans=-inf;
        for(int i=1;n-i>=0;i++)
        {
            memset(dp,0,sizeof(dp));
            for(int j=i;n-j>=0;j++)
            {
                for(int k=1;n-k>=0;k++) dp[k]+=a[j][k];
                
                int t=0;
                for(int k=1;n-k>=0;k++)
                {
                    t+=dp[k];
                    ans=max(t,ans);
                    t=max(t,0);
                }
            }
        }
        
        printf("%d\n",ans);
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator