Bzoj 1084 Max Sub-matrix Finally, it's over.

Source: Internet
Author: User

The first to see this problem, because I think M <= 2, so I think this is a water problem, go back and think a bit. In the evening came to the engine room, but I have to admit that the details of the success or failure. In one hours ago I have already written the main body of the algorithm, but is always WA, why is all kinds of careless, really want to pinch to death. One hours was wasted in vain. I hope I can become stronger tomorrow. After today's painful lesson.

This problem is not difficult. Use D[i][j][k] to represent the state. I represents the first few lines, J indicates how many matrices were taken before, and K represents the state of the previous row. That is, the matrix of the previous line. If k = = 0 then no matrix extends to the previous row, if k = = 1, then there is a matrix extends to the left of the previous row of the number, k = = 2 o'clock Then there is a matrix extends to the right of the previous line of the number, k = = 3 o'clock, respectively, two matrices extend to the previous two numbers. When k = = 4 o'clock there is a matrix that extends to two numbers on the previous line. Then the state transfer equation should not be difficult to write. Careful and careful, then careful. Modesty, modesty, and humility.

1#include <cstdio>2#include <iostream>3#include <cstring>4 #defineINF 0X3FFFFFFF5 #defineRep (i,j,k) for (int i = j; I <= K; i++)6 #defineMAXN 1207 using namespacestd;8 9 intd[maxn][ the][5] = {0};Ten inta[maxn][3] = {0}; One  A intRead () - { -     ints =0, t =1;Charc =GetChar (); the      while( !IsDigit (c)) { -         if(c = ='-') T =-1; c =GetChar (); -     } -      while(IsDigit (c)) { +s = S *Ten+ C-'0'; c =GetChar (); -     } +     returnS *T; A } at  - intMain () - { -     intn = Read (), M = Read (), k =read (); -Rep (I,0, N) Rep (J,0, K) Rep (L,0,4) D[i][j][l] =-INF; -d[0][0][0] =0; inRep (I,1, N) { -Rep (J,1, M) { toA[I][J] =read (); +         } -     } theRep (I,0, N-1) *Rep (J,0, K) { $            if(M = =1 ){Panax NotoginsengRep (L,0,1) d[i+1][j][0] = max (d[i+1][j][0],d[i][j][l]); -d[i+1][j][1] = max (d[i+1][j][1],d[i][j][1]+a[i+1][1]); thed[i+1][j+1][1] = max (d[i+1][j+1][1],d[i][j][0]+a[i+1][1]); +            } A            Else{ theRep (L,0,4) d[i+1][j][0] = max (d[i+1][j][0],d[i][j][l]); +d[i+1][j][1] = max (d[i+1][j][1],d[i][j][1]+a[i+1][1]); -d[i+1][j][1] = max (d[i+1][j][1],d[i][j][3]+a[i+1][1]); $d[i+1][j+1][1] = max (d[i+1][j+1][1],d[i][j][0]+a[i+1][1]); $d[i+1][j+1][1] = max (d[i+1][j+1][1],d[i][j][2]+a[i+1][1]); -d[i+1][j+1][1] = max (d[i+1][j+1][1],d[i][j][4]+a[i+1][1]); -                 thed[i+1][j][2] = max (d[i+1][j][2],d[i][j][2]+a[i+1][2]); -d[i+1][j][2] = max (d[i+1][j][2],d[i][j][3]+a[i+1][2]);Wuyid[i+1][j+1][2] = max (d[i+1][j+1][2],d[i][j][0]+a[i+1][2]); thed[i+1][j+1][2] = max (d[i+1][j+1][2],d[i][j][1]+a[i+1][2]); -d[i+1][j+1][2] = max (d[i+1][j+1][2],d[i][j][4]+a[i+1][2]); Wu                 -d[i+1][j][3] = max (d[i+1][j][3],d[i][j][3]+a[i+1][2]+a[i+1][1]); Aboutd[i+1][j+1][3] = max (d[i+1][j+1][3],d[i][j][1]+a[i+1][2]+a[i+1][1]); $d[i+1][j+1][3] = max (d[i+1][j+1][3],d[i][j][2]+a[i+1][2]+a[i+1][1]); -d[i+1][j+2][3] = max (d[i+1][j+2][3],d[i][j][0]+a[i+1][2]+a[i+1][1]); -d[i+1][j+1][3] = max (d[i+1][j+1][3],d[i][j][4]+a[i+1][2]+a[i+1][1]); -                 Ad[i+1][j][4] = max (d[i+1][j][4],d[i][j][4]+a[i+1][2]+a[i+1][1]); +Rep (L,0,3) d[i+1][j+1][4] = max (d[i+1][j+1][4],d[i][j][l]+a[i+1][2]+a[i+1][1]); the            } -       } $       intans; theans = max (d[n][k][0],d[n][k][1]); the       if(M = =2) Rep (L,2,4) ans =Max (ans,d[n][k][l]); thecout<<ans<<Endl; the       return 0; -}
1084: [SCOI2005] Maximum sub-matrix time limit:10 Sec Memory limit:162 MB
submit:1851 solved:927
[Submit] [Status] [Discuss] Description

Here is a n*m matrix, please select the K sub-matrix, so that the K sub-matrix score of the sum of the largest. Note: The selected K-matrices cannot overlap each other.

Input

The first behavior is n,m,k (1≤n≤100,1≤m≤2,1≤k≤10), and the next n lines describe the score of each element in each row of the matrix (the absolute value of each element does not exceed 32767).

Output

There is only one behavior k the sum of the sub-matrices is the maximum number.

Sample Input3 2 2
1-3
2 3
-2 3Sample Output9

Bzoj 1084 Max Sub-matrix Finally, it's over.

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.