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

Re:一遍过,太感动了

Posted by shenhaomin at 2021-07-03 11:28:06 on Problem 1050
In Reply To:一遍过,太感动了 Posted by:shenhaomin at 2021-07-03 11:27:55
#include <iostream>
#include <cstring>

using namespace std;

int n,flag;

int fun(int w[128])
{
    int i;
    int dp[128];
    dp[0]=w[0];
    int MAX=dp[0],p=1;
    for(i=1;i<n;i++)
    {
        if(dp[i-1]+w[i]>w[i])
        {
            dp[i]=dp[i-1]+w[i];
            p++;
        }
        else
            dp[i]=w[i];
        if(dp[i]>MAX)
            MAX=dp[i];
    }
    if(flag&&p==n)
    {
        if(w[0]<w[n-1])
            MAX-=w[0];
        else
            MAX-=w[n-1];
    }
    return MAX;
}

int main()
{
    int a[128][128];
    int total[128][128];
    int w[128];
    int i,j,ans;
    while(cin>>n)
    {
        ans=flag=0;
        for(i=0;i<n;i++)
            for(j=0;j<n;j++)
            {
                cin>>a[i][j];
                total[i][j]=a[i][j];
            }
        for(i=1;i<n;i++)
            for(j=0;j<n;j++)
                total[i][j]+=total[i-1][j];
        for(i=0;i<n;i++)
        {
            for(j=i,flag=0;j<n;j++)
            {
                if(i==0&&j==n-1)
                    flag=1;
                for(int t=0;t<n;t++)
                {
                    if(i==0)
                        w[t]=total[j][t];
                    else
                        w[t]=total[j][t]-total[i-1][t];
                }
                int ansl=fun(w);
                if(ansl>ans)
                    ans=ansl;
            }
        }
        cout<<ans<<endl;
    }
    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