Topic Background
In the advent of adolescence, why things.
Answer: "hyperthyroidism, hyperthyroidism, again hyperthyroidism; starve, starve, and starve." " Title Description
The Li Buffalo, which is in a certain period of time, has been in a state of starvation recently because of a more developed digestive system. One day in class, just as he was so hungry, he suddenly flashed a giant big table with a n*m (n and m<=200) moment, and was at the midpoint of the side of the big table. The table was divided to n*m a small square, each of which had a large, round, large dinner plate filled with food that made the Li Buffalo yearn. Li Buffalo has divided all the food on the table according to the amount of energy it can provide (some of it is negative, because it has to be pulled), he decides to eat it from his place to the other side of the table, but he eats a habit-eat only food in front of himself or in front of the left or right in front of the plate.
Since the Li Buffalo is hungry and wants to get the most energy, he has given you the problem.
The starting point for each set of data is below the middle position of the last line. input/output format
Input format:
[Input data:]
The first behavior is M n. (n is odd), Li Buffalo starts at the bottom of the last line in the middle of the
Next is the digital array of the m*n.
A total of M rows, n digits per line. The numbers are separated by spaces. Represents the energy provided by the food on the plate of the lattice.
The numbers are all integers.
Output format:
[Output data:]
A number that is the maximum energy value you find. input/Output sample
Input Sample # #:
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 # # of output:
Description
Eat fast. Eat fast. Eat fast. Code
#include <iostream> using namespace std; int n,m; int a[205][205],f[205][205],maxn; int
dr[3][2]={{-1,0},{-1,-1},{-1,1}}; BOOL PD (int x,int y) {if (y<=0| |
Y>n) return false;
return true; } void Search (int x,int y) {if (f[x][y]!=0| |
X==1) return;
for (int i=0;i<3;i++) {int nx=x+dr[i][0],ny=y+dr[i][1];
if (PD (Nx,ny)) {search (Nx,ny);
F[x][y]=max (F[x][y],f[nx][ny]+a[x][y]);
}}} int main () {cin>>m>>n;
for (int i=1;i<=m;i++) {for (int j=1;j<=n;j++) {cin>>a[i][j];
if (i==1) f[i][j]=a[i][j];
}} int x=m,y= (n+1)/2;
Search (x, y);
Search (x,y+1);
Search (x,y-1);
Maxn=max (Max (f[x][y],f[x][y+1]), f[x][y-1]);
cout<<maxn;
return 0; }