Do not think, I am not bored to brush NOIP2000 topic, but the teacher used the test to tell us that our DP is very weak, so we come to find a way DP to do
Also, the problem seems to have nothing to do with the matrix fetch.
Title: give you a n*n square (small very, n only 10), you can go right or down one step, and take away the numbers, you have to fetch two times, output the last number of
First, this is a checkerboard DP, we from the top left to the right under the DP is good, I started to play the record location method, run two times DP, however, the pit, then we have to carefully analyze the problem, n is small, small to you can open to 6 dimensions will not burst memory, so bold to improve the dimension bar, in the analysis of In fact, the two paths we're looking for are final and maximum
So we can open the four-dimensional DP array dp[i][j][k][l], which means that the first point is (I,J) The second point is (k,l) the transfer equation is dp[i][j][k][l] = max (all the points up to the point) + map[i][j] + map[k][l];
Subtract a map value if the two point is heavy;
#include <algorithm>#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<cmath>using namespaceStd;typedefLong Longll;intmap[ -][ -];intdp[ -][ -][ -][ -];intMain () {intN; scanf ("%d",&N); intx,y,v; for(SCANF ("%d%d%d", &x,&y,&v); X! =0; scanf ("%d%d%d",&x,&y,&v)) Map[x][y]=v; for(inti =1; I <= N; ++i) for(intj =1; J <= N; ++j) for(intK =1; k <= N; ++k) for(intL =1; l <= N; ++l) {Dp[i][j][k][l]= Max (max (Dp[i-1][j][k-1][l],dp[i-1][j][k][l-1]), Max (Dp[i][j-1][k][l-1],dp[i][j-1][k-1][L]) + map[i][j] +Map[k][l]; if(i = = k && J = =l) dp[i][j][k][l]-=Map[i][j]; } printf ("%d\n", Dp[n][n][n][n]); return 0;}
Check count (DP) (NOIP2000)