"Algorithmic Learning Notes" 77. Dynamic planning of two-line chessboard SJTU OJ 1263 paper to go to the paper

Source: Internet
Author: User
Tags repetition

DP[I][J][K][L]

Represents the maximum level of enthusiasm from (I,J) to (from) to (k,l) at the same time.

(= = three-dimensional optimization has time to engage in. )

Note that there is a place that is not the same as other people, I am the judge if the end of the repetition, the direct subtraction of the point of kindness, indicating that there is a pass through the position of the person's kindness is 0;

#include <iostream>using namespacestd;intmap[ -][ -]={0},dp[ -][ -][ -][ -]={0};intMaxintAintb) {returnA>b?a:b;}intMainintargcChar Const*argv[]) {        intn,m; CIN>>n>>m;  for(intI=1; i<=n;i++)         for(intj=1; j<=m;j++) Cin>>Map[i][j];  for(intI=1; i<=n;i++)         for(intj=1; j<=m;j++)             for(intk=1; k<=n;k++)                 for(intL=1; l<=m;l++) {Dp[i][j][k][l]=Max (//each route is derived from the previous two pointsMax (dp[i-1][j][k-1][l],dp[i-1][j][k][l-1]), Max (Dp[i][j-1][k-1][l],dp[i][j-1][k][l-1])                                      )                    + map[i][j]+Map[k][l]; if(i==k&&j==l)//If you pass the same point, subtract a kindness value, because that road of repetition can be thought of as 0 kindness.dp[i][j][k][l]-=Map[i][j]; } cout<<dp[n][m][n][m]<<Endl; return 0;}

"Algorithmic Learning Notes" 77. Dynamic planning of two-line chessboard SJTU OJ 1263 paper to go to the paper

Related Article

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.