HDU2686 Multi-decision DP

Source: Internet
Author: User

Back and forth can be seen as two disjoint paths from (N,n)

Dp[k][x1][y1][x2][y2] = max (dp[k-1][x1-1][y1][x2-1][y2],dp[k-1][x1-1][y1][x2][y2-1],dp[k-1][x1][y1-1][x2-1][y2 ],DP[K-1][X1][Y1-1][X2][Y2-1])
K is the number of steps
K related to X1,y1, can be reduced to three-dimensional

//Multi-decision DP//Dp[k][x1][y1][x2][y2] = max (dp[k-1][x1-1][y1][x2-1][y2],dp[k-1][x1-1][y1][x2][y2-1],dp[k-1][x1][y1-1][x2-1][ Y2],DP[K-1][X1][Y1-1][X2][Y2-1])//K is the number of steps//K related to x1,y1, can be reduced to three-dimensional#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#include<string>#include<stack>#include<queue>using namespacestd;Const intINF = (1<< to)-1;Const intMAXN = 3e1+Ten;intdp[2*MAXN] [MAXN] [MAXN];intA[MAXN][MAXN];intt1[2],t2[2];intMain () {intN;  while(~SCANF ("%d",&N)) {         for(intI=1; i<=n;i++){             for(intj=1; j<=n;j++) {scanf ("%d",&A[i][j]); }} memset (DP,0,sizeof(DP)); //dp[0][1][1] = a[1][1];         for(intI=1; i<=2*n-3; i++){             for(intj=1; j<=i+1&&j<=n-1; j + +) {//X1 Meet                    if(i+2-j>n)Continue;//Y1 Meet                 for(intk=j+1; k<=i+1&&k<=n;k++){                     if(i+2-k>n-1)Continue; t1[0] =J; t1[1] = J1; t2[0] =K; t2[1] = k1;  for(intL=0;l<2; l++){                         for(intR=0;r<2; r++){                            if(T1[l]==t2[r])Continue; DP[I][J][K]= Max (dp[i][j][k],dp[i-1][t1[l]][t2[r]]); }} Dp[i][j][k]+ = a[j][i+2-j]+a[k][i+2-K]; /*cout<<i<< "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl; cout<< "Debug" <<endl;*/} }} dp[2*n-2][n][n] = dp[2*n-3][n-1][n] +A[n][n]; cout<<dp[2*n-2][n][n]+a[1][1]<<Endl; }    //cout << "Hello world!" << Endl;    return 0;}
View Code

HDU2686 Multi-decision DP

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.