Interval DP brute force enumeration + Dynamic Planning hdu1081

Source: Internet
Author: User

F-Maximum child rectangle
Time Limit: 1000 ms memory limit: 10000kb 64bit Io format: % i64d & % i64u
Submit

Status
Description
Given a two-dimenstmarray of positive and negative integers, a sub-rectangle is any contiguous sub-array of size 1*1 or greater located within the whole array. the sum of a rectangle is the sum of all the elements in that rectangle. in this problem the sub-rectangle with the largest sum is referred to as the maximal sub-rectangle.
As an example, the maximal sub-rectangle of the array:

0-2-7 0
9 2-6 2
-4 1-4 1
-1 8 0-2
Is in the lower left corner:

9 2
-4 1
-1 8
And has a sum of 15.
Input
The input consists of an n * n Array of integers. the input begins with a single positive integer n on a line by itself, indicating the size of the square two-dimen=array. this is followed by N ^ 2 integers separated by whitespace (spaces and newlines ). these are the N ^ 2 integers of the array, presented in row-Major Order. that is, all numbers in the first row, left to right, then all numbers in the second row, left to right, etc. N may be as large as 100. the numbers in the array will be in the range [-127,127].
Output
Output the sum of the maximal sub-rectangle.
Sample Input
4
0-2-7 0 9 2-6 2
-4 1-4 1-1

8 0-2
Sample output
15

<Span style = "color: # 3333ff;">/* revoke Author: grant yuan time: 2014.7.19 Source: hdu1081 algorithm: Brute Force enumeration + Dynamic Planning explain: brute-force enumeration of sum [I] of each element from row K1 to row K2, then sum [I] is summed up in the largest subsequence _______________________________________________________________________________________________________________________________________________________ Lude <iostream> # include <cstdio> # include <cstring> # include <cstdlib> # include <functional> # include <algorithm> using namespace STD; int A [105] [105]; int L; int sum [105]; int DP [105]; int main () {While (~ Scanf ("% d", & L) {for (INT I = 0; I <L; I ++) for (Int J = 0; j <L; j ++) scanf ("% d", & A [I] [J]); int ans =-9999999, ans1; For (INT k1 = 0; k1 <L; k1 ++) for (INT k2 = 0; K2 <L; K2 ++) {memset (DP, 0, sizeof (DP); memset (sum, 0, sizeof (SUM); For (INT I = 0; I <L; I ++) {for (Int J = k1; j <= k2; j ++) {sum [I] + = A [I] [J] ;}for (INT m = 0; m <L; m ++) {DP [M + 1] = max (DP [m] + sum [m], sum [m]);} ans1 = DP [1]; for (INT d = 1; D <= L; D ++) if (DP [d]> ans1) ans1 = DP [d]; If (ans1> ans) ans = ans1 ;}} printf ("% d \ n", ANS) ;}}</span>

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.