Check count (DP) (NOIP2000)

Source: Internet
Author: User

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)

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.