2728: Picking peanuts (Digital Gold tower variant)

Source: Internet
Author: User

2728: Peanut Picking

    • View
    • Submit
    • Statistics
    • Questions

Total time limit:

1000ms

Memory Limit:

65536kB

Describe

Hello Kitty wants to pick up some peanuts and give her favorite Mickey Mouse. She came to a rectangular peanut land with a grid-like path (eg), went in from the northwest corner, and came out in the southeast corner. The intersection of each road in the field has a peanut seedling, which has a number of peanuts, after a peanut seedling can take off all the peanuts above it. Hello Kitty can only go east or south, not west or north. Ask Hello Kitty How many peanuts can be picked up.

Input

The first line is an integer t, representing how many sets of data are in total. 1<=t <= 100
Next is the T-group data.

The first line of data for each group is two integers, representing the number of rows R and C (1<= r,c <=100) of the peanut seedlings, respectively.
The next r row data for each group of data, from north to south, describes the situation of each line of peanut seedlings in turn. Each row of data has a C integer, which describes the number of peanuts on each peanut seedling in the line from west to east (0<= m <= 1000).

Output

For each set of input data, output one line, the content is Hello Kitty can pick up the number of peanuts.

Sample input

2

2 2

1 1

3 4

2 3

2 3 4

1 6 5

Sample output

8

16

#include <cstdio>#include<iostream>#include<cstring>using namespacestd;inta[1001][1001],f[1001][1001],n,m,t;intMain () {scanf ("%d",&t);  while(t--) {scanf ("%d%d",&n,&m); Memset (F,-1,sizeof(f)); Memset (A,0,sizeof(a));  for(intI=1; i<=n;i++)         for(intj=1; j<=m;j++) scanf ("%d",&A[i][j]);  for(intI=0; i<=n+1; i++)         for(intj=0; j<=m+1; j + +) F[i][j]=max (f[i-1][j],f[i][j-1])+A[i][j]; printf ("%d\n", f[n+1][m+1]); }        return 0;}

2728: Picking peanuts (Digital Gold tower variant)

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.