HDU 1081 DP Problem: Maximum sub-matrix and

Source: Internet
Author: User

Topic links

Test instructions: give you a n*n matrix, find the maximum sub-matrices of this matrix and

#include <iostream> #include <cstdio> #include <string.h>using namespace std; #define INF- 0x3f3f3f3fint Field[105][105],dp[105];int Main () {    int n;    while (~SCANF ("%d", &n))    {        int maxn=0;        memset (field,0,sizeof (field));        Memset (Dp,0,sizeof (DP));        for (int i=1;i<=n;i++)          for (int j=1;j<=n;j++)            {                scanf ("%d", &field[i][j]);                FIELD[I][J]+=FIELD[I-1][J];            } Process the first I and for       (int i=1;i<=n;i++) for         (int j=0;j<i;j++)//enumeration set two frames for            (int k=0;k<=n;k++)//Run DP            {                dp[k]=field[i][k]-field[j][k];                if (dp[k-1]>0)                    dp[k]+=dp[k-1];                Maxn=max (Maxn,dp[k]);            }        printf ("%d\n", MAXN);    }    return 0;}

Analysis: Classic DP problem: To find the maximum subsequence and, but this problem of deformation is no longer a one-dimensional, but two-dimensional, so need to set

Take a look at the two frames and then run one-dimensional DP between the two frames, a very ingenious idea! DP is used to hold the maximum value of the previous matrix

HDU 1081 DP Problem: Maximum sub-matrix and

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.