# (Two-dimensional map DP) Luo Gu P1508 Likecloud- eat, eat, eat (universal / increase -)

Title 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 Format

[Input data:]

First line m n. (N is odd), a buffalo Li starts below the last row of the intermediate

Next Inmerse Matrix for the m * n number.

There are m rows of n digits. Separated by a space between a digital representative of the energy of the plate of food on the grid can be provided.

All integer numbers.

Output Format

[Output Data:]

A number, the maximum value of the energy that you find.

Sample input and output

Input # 1
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
Output # 1
41

Description / Tips

eat fast! eat fast! eat fast!

f [i] [j] represents the i, j, maxE

From three directions, can be pushed.

f[i][j]=max(f[i-1][j-1],f[i-1][j],f[i-1][j+1]);

Code:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,m;
int a[230][230],ans=-12000;
int f[230][230];
bool book[203][203];

inline int max(int x,int y)
{
return x>y?x:y;
}
int main()
{
memset(a,-9999,sizeof(a));
cin>>m>>n;
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
{
cin>>a[i][j];
}
int mid=(n+1)/2;
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
f[i][j]=max(f[i-1][j],max(f[i-1][j-1],f[i-1][j+1]))+a[i][j];
cout<<max(max(f[m][mid],f[m][mid-1]),f[m][mid+1]);
return 0;
}

Guess you like

Origin www.cnblogs.com/little-cute-hjr/p/11410544.html