VIJOS-P1364 Likecloud- eat, eat, eat

JDOJ 1465: VIJOS-P1364 Likecloud- eat, eat, eat

https://neooj.com/oldoj/problem.php?id=1465

Description

        In the midst of a particular period Lee Buffalo Since the digestive system is relatively developed, it has recently been in a state of hunger. One day in class, just as he's hungry dizziness, eyes suddenly flashed a n * m (n and m <= 200) of rectangular giant large dining table, while he is at the side of the big dining table the midpoint below. In order table is divided into n * m small squares, each square has a circular shape in giant large tray, so that the above Li filled food buffalo dreaming. Lee Buffalo on the table has all of their food energy can provide hit points (some of which are negative, because you want to eat diarrhea), he decided to eat the other side of the table from where you are, but he has a habit of eating - eating plate of food in front of their own front or left or right front. Since Lee Buffalo hungry do not want to have brains, and he wants to get the most energy, so he referred the matter to you. The starting point of each set of data is below the last row of the middle position!

Input

[Data Input:] m first row n (n is odd), Li buffalo beginning followed by a number of m * n Inmerse Matrix there are m row below the middle of the last row, each row n digits.. separated by spaces between numbers. energy food tray on behalf of the grid can provide digital all integers.

Output

[Output data:] a number, the maximum value of the energy that you find.

Sample Input

6 7 16 4 3 12 6 0 3 4 -5 6 7 0 0 2 6 0 -1 -2 3 6 8 5 3 4 0 0 -2 7 -1 7 4 0 7 -5 6 0 -1 3 4 12 4 2

Sample Output

41

HINT

eat fast! eat fast! eat fast! 

 

Giant simple idea, I personally think the state transition equation is also very good thought.

It is this initial position, the pit father.

The rest is just details.

Come, AC together

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m;
int a[201][201];
int dp[201][201];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            scanf("%d",&a[i][j]);
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=m;i++)
        dp[1][i]=a[1][i];
    for(int i=2;i<=n;i++)
    {
        for(int j=2;j<m;j++)
            dp[i][j]=max(dp[i-1][j],max(dp[i-1][j-1],dp[i-1][j+1]))+a[i][j];
        dp[i][1]=max(dp[i-1][1],dp[i-1][2])+a[i][1];
        dp[i][m]=max(dp[i-1][m],dp[i-1][m-1])+a[i][m];
    }
    printf("%d",max(dp[n][m/2],max(dp[n][m/2+1],dp[n][m/2+2])));
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/fusiwei/p/11237979.html