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

核心代码

Posted by 08122224 at 2021-11-20 22:42:29 on Problem 1050
int findMax(int32_t *src, int32_t *tempSum, int32_t *maxSum, int len)
{
    int i = 0;
    int j = 0;
    int k = 0;
    int index = 0;
    int temp = 0;
    int size = len * (len + 1) / 2;
    int max = maxSum[0];

    for (i = 1; i < len; ++i) {
        index = 0;
        for (j = 0; j < len; ++j) {
            temp = 0;
            for (k = j; k < len; ++k) {
                temp += src[k * len + i];
                tempSum[index] += temp;
                if (tempSum[index] > maxSum[index]) {
                    maxSum[index] = tempSum[index];
                }
                if (tempSum[index] < 0) {
                    tempSum[index] = 0;
                }
                ++index;
            } 
        } 
    }

    for (i = 0; i < size; ++i) {
        if(maxSum[i] > max) {
            max = maxSum[i];
        }
    }
    return max;
}


//i=0的时候,对tempSum和maxSum初始化,全负数也可以过

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