POJ1050 To the MAX question

Source: Internet
Author: User

POJ1050 To the MAX question
Question

Give a matrix of N * N to find a child matrix to maximize the sum of the Child matrix. (N <= 100)

Ideas

One-dimensional situations are classic "Maximum continuity and problems ". We want to reduce the problem of two dimensions to one dimension. We enumerate the highest and lowest layers, add the values in the middle to a tmp array, and then use the tmp array to "Maximum continuity and problems" to constantly update ans. The resulting ans must be the largest submatrix.

Code
# Include
  
   
# Include
   
    
Using namespace std; const int INF = 1000000000; const int maxn = 110; int n; int s [maxn] [maxn]; int tmp [maxn]; int dp [maxn]; int main () {scanf ("% d", & n); for (int I = 0; I <n; I ++) {for (int j = 0; j <n; j ++) scanf ("% d", & s [I] [j]);} int ans =-INF; for (int I = 0; I <n; I ++) {for (int j = I; j <n; j ++) {memset (tmp, 0, sizeof (tmp )); for (int t = I; t <= j; t ++) {for (int c = 0; c <n; c ++) tmp [c] + = s [t] [c];} // for tmp dp ans = max (ans, tmp [0]); int temp = tmp [0]; for (int I = 1; I <n; I ++) {if (temp <= 0) {temp = tmp [I];} else {temp + = tmp [I];} ans = max (ans, temp) ;}} printf ("% d \ n", ans); return 0 ;}
   
  

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.