P1508 Likecloud-Eat, eat, eat, p1508likecloud-eat

Source: Internet
Author: User

P1508 Likecloud-Eat, eat, eat, p1508likecloud-eat
Background

Why is it in adolescence?

Answer: "hyperthyroidism, hyperthyroidism, and hyperthyroidism; hunger, hunger, and hunger !"

Description

Li Da buffalo, which is in a certain period of time, has been in hunger recently due to its developed digestive system. One day, when he was dizzy, he suddenly showed a giant dining table of n * m (n and m <= 200, and you are at the center of the big table. The dining table is divided into n * m small squares, each of which has a circular giant dining plate filled with food that Lida buffalo is thinking about. Li Da buffalo has divided all the food on the table according to the energy it can provide (some are negative because it has to be diarrhea ), he decided to eat the other side of the dining table from where he was, but he had a habit of eating only the food in his front, left front, or right front disk.

Li Da buffalo was so hungry that he wanted to get the most energy, so he gave it to you.

The starting point of each group of data is below the center of the last row!

Input/Output Format

Input Format:

 

[Input data:]

The first act is m n. (n is an odd number). Li Da Buffalo starts at the bottom of the middle of the last row.

Next is the m * n numeric array.

There are m rows in total, n numbers in each row. Numbers are separated by spaces, representing the energy that the food in the disk on the grid can provide.

The numbers are all integers.

 

Output Format:

 

[Output Data:]

A number is the maximum energy value you can find.

 

Input and Output sample input sample #1:
6 716 4 3 12 6 0 34 -5 6 7 0 0 26 0 -1 -2 3 6 85 3 4 0 0 -2 7-1 7 4 0 7 -5 60 -1 3 4 12 4 2
Output sample #1:
41
Description

Eat now! Eat now! Eat now!

 

For memory-based search, note that x = 1.

 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 using namespace std; 7 const int MAXN=233; 8 void read(int &n) 9 {10     char c='+';int x=0;bool flag=0;11     while(c<'0'||c>'9')12     {c=getchar();if(c=='-')flag=1;}13     while(c>='0'&&c<='9')14     {x=x*10+(c-48);c=getchar();}15     flag==1?n=-x:n=x;16 }17 int n,m;18 int a[MAXN][MAXN];19 int dp[MAXN][MAXN];20 int xx[5]={-1,-1,-1};21 int yy[5]={-1,0,+1};22 int M_S(int x,int y)23 {24     if(x==1)25     {26         if(!dp[x][y])27             dp[x][y]=a[x][y];28         return dp[x][y];29     }30         31     if(dp[x][y])32         return dp[x][y];33     for(int i=0;i<3;i++)34     {35         int wx=x+xx[i];36         int wy=y+yy[i];37         if(wx>=1&&wx<=n&&wy>=1&&wy<=m)38         dp[x][y]=max(dp[x][y],M_S(wx,wy)+a[x][y]);39     }40     return dp[x][y];41 }42 int main()43 {44     read(n);read(m);45     for(int i=1;i<=n;i++)46         for(int j=1;j<=m;j++)47             read(a[i][j]);48     M_S(n,m/2+1);49     M_S(n,m/2);50     M_S(n,m/2+2);51     int ans=max(max(dp[n][m/2],dp[n][m/2+1]),dp[n][m/2+2]);52     printf("%d",ans);53     return 0;54 }

 

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.