POJ 1050 to the Max

Source: Internet
Author: User

Test instructions: Maximum sub-matrices and problems.

Solution: N^2 Enumeration of a matrix, as follows

A11 A12 ... a1i ... a1j ... a1n

A21 A22 ... a2i ... a2j ... a2n

...

An1 an2 ... ani ... anj ann

To cite a matrix from I to J, add the value of each row and then get an array of {a1ij, A2ij, ..., anij}, the maximum number of sub-segments and (equation: maxn[i] = max (Maxn[i-1] + a[i], a[i])), and the maximum value of all the maximum child segments is the answer.

Code:

#include <stdio.h> #include <iostream> #include <algorithm> #include <string> #include < string.h> #include <math.h> #include <limits.h> #include <time.h> #include <stdlib.h># include<map> #include <queue> #include <set> #include <stack> #include <vector> #define LL    Long longusing namespace Std;int main () {int n;    int a[105][105];        while (~SCANF ("%d", &n)) {int ans =-2000000;        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 + +) {int Maxx =-2000000;                    for (int k = 0; k < n; k++) {int sum = 0;                    for (int l = i; l <= J; l++) sum + = A[k][l];                    Maxx = max (maxx + sum, sum);                ans = max (Maxx, ANS);        }    } printf ("%d\n", ans); } return 0;}

PS: Overflow after initializing Maxx to Int_min plus negative number Qaq

POJ 1050 to the Max

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.