Nyoj 61 Pass the note (a)

Source: Internet
Author: User

Tag: color a ring class coordinate STD for span ret

Dual Line DP

#include <iostream>#include<algorithm>#include<ctype.h>#include<string>#include<string.h>#include<vector>#include<queue>using namespacestd;intdp[ the][ -][ -];//compressed space dp[x1+y1][x1][x2]; //values known as X1+Y1, X1, and x2, combined with x1 + y1 = x2 + y2 can determine x1,y1,x2,y2 four valuesintmp[ -][ -];intMaxintAintBintCintd) {    if(a>=b && a>=c && a>=d)returnA; Else if(B>=a && b>=c && b>=d)returnb; Else if(C>=a && c>=b && c>=d)returnC; Else if(D>=a && d>=c && d>=b)returnD;}intMain () {intT; CIN>>T;  while(t--)    {        intM,n; CIN>>m>>N;  for(intI=1; i<=m;i++)        {             for(intj=1; j<=n;j++) {cin>>Mp[i][j]; }        }        intK,x1,y1,x2,y2;  for(k=0; k<=m+n;k++)             for(x1=0; x1<=m;x1++)                 for(x2=0; x2<=m;x2++) dp[k][x1][x2]=0;  for(k=2; k<=m+n;k++)        {             for(x1=1; x1<=m;x1++)//(x, y) as one of the coordinates, with K to find the corresponding other point, traverse K and all (x, y) can get all the values of Dp[k][x][y]            {                 for(x2=1; x2<=m;x2++) {y1= K-X1; Y2= K-x2; if(y1<=n && y2<=n && y1>=1&& y2>=1)//no cross-border                    {                        if(x1! = x2 && y1! = y2)//do not intersect                        {                            intV1 = dp[k-1][x1-1][x2-1] + Mp[x1][y1] +Mp[x2][y2]; intV2 = dp[k-1][X1][X2] + mp[x1][y1] +Mp[x2][y2]; intV3 = dp[k-1][x1-1][X2] + mp[x1][y1] +Mp[x2][y2]; intV4 = dp[k-1][x1][x2-1] + Mp[x1][y1] +Mp[x2][y2]; DP[K][X1][X2]=Max (V1,V2,V3,V4); } }}} cout<<dp[m+n-1][m][m-1]<<Endl; }        return 0;} 

Nyoj 61 Pass the note (a)

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.