Abstract 1284 through a peanuts

Description [title]

Hello Kitty want to pick peanuts gave her favorite Mickey Mouse. She came to a rectangular grid pattern peanut road (as shown below), go in from the northwest, the southeast corner of it. Ground for each road intersection has a peanut seedlings planted, a number of the above peanuts, peanut seedlings can be picked after a peanut all the above it. Hello Kitty can only go east or south, west or north can not go. Q. Hello Kitty maximum number of peanuts to be able to pick.

[Enter]

The first line is an integer T , on behalf of a total of how many sets of data. . 1 T 100

Next is T set of data.

The first line of each data is a two integers, representing the number of rows of peanut seedlings R and columns  C ( . 1 R , C 100 )

Next, each R data of the line data, the case of peanut seedlings per row from north to south. Each row of data hasC integers, in order from west to east on peanut seedlings per describes the number of the row peanutsM(0≤M≤1000)。

[Output]

Each set of input data, output line, Hello Kitty content to be able to pick the most number of pieces of peanuts.

[Sample input]

2
2 2
1 1
3 4
2 3
2 3 4
1 6 5

[Sample Output]

8 
16 


Code:

#include <the iostream>
#include <cstdio>
#include <the cmath>
#include <CString>
#include <the cstdlib>
#include <algorithm>
the using namespace STD;
int ANS [110];
int main ()
{
int T;
CIN> > T;
int B = T;
the while (T--)
{
int n-, m;
CIN >> >> n-m;
int A [n-2 +] [m + 2] = {}, F [n-2 +] [m + 2] = {} ; // + 2 as defined herein, is to prevent the array bounds, as the first data if the foregoing will go out of range, so that all the data to the "lower right corner" a displacement unit, so 0 can empty out to make a first row and first column of the data added
for (int i = 1; i <= n; i ++) // starting from 1 is to prevent cross-border
{
for (int J = 1; J < m =; J ++)
{
CIN >> A [I] [J];
F [I] [J] = A [I] [J]; // this initialization sequences are not the same and rises up, it initializes itself to
}
}
for (int I =. 1; I <= n-; I ++)
{
for(int j=1;j<=m;j++)
{
f[i][j]=a[i][j]+max(f[i-1][j],f[i][j-1]);
ans[t]=max(ans[t],f[i][j]);
}
}
}
for(int i=b-1;i>=0;i--)
cout<<ans[i]<<endl;
return 0;
}

(I do not know my indentation Why was eaten, Minato live to see it, really I do not want to waste time on it)

Guess you like

Origin www.cnblogs.com/57xmz/p/12466129.html