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