zoukankan      html  css  js  c++  java
  • Eating Peach (peach)

    Description


    On this day, the little monkey went looking for food. He came to a rectangular peach garden with grid-like roads (as shown in the picture below), entered from the northwest corner and exited from the southeast corner. There is a peach tree planted at every intersection of roads in the field, with several peaches on it, and all the peaches on it are picked after passing a peach tree. The little monkey can only go east or south, not west or north. Q: How many peaches can the little monkey pick at most?

    Format


    Input

    The first line is an integer (T (1 leq T leq 70)), which represents how many sets of data there are.
    Next is the (T) group data. The first row of each group of data is two integers, representing the number of rows (R) and the number of columns (C) of the peach tree ((1 leq R, C<100)).
    The next (R) rows of data in each set of data describe the situation of each row of peach trees in turn from north to south.
    Each row of data has C integers, describing the number of peaches (M) on each peach tree in the row in order from west to east ((0 leq M<1000)).

    Output

    For each group of input data, output one line, the content is the number of peaches that the monkey can pick the most.

    Sample


    Input

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

    Output

    8
    16
    

    Sample Explanation

    1. Representatives need to process 2 sets of data
    2. Represents the number of rows (R) and the number of columns (C) of the peach tree
    3. The number of peaches per peach tree in the row from west to east (M), (C) peach trees in each row
    4. The number of peaches on each peach tree from west to east is (M), (R) in total
    5. The second set of data: peach trees have 2 rows and 3 columns
    6. On the first row from west to east, there are 2, 3, 4 peaches on each peach tree, a total of 3 peach trees
    7. In the second row, from west to east, there are 1, 6, 5 peaches on each peach tree, 3 peach trees in total

    Sample Code


    #include<iostream>
    #include<cmath>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    using namespace std;
    
    int t,r,c;
    int a[105][105];
    int main() {
    	freopen("peach.in","r",stdin);
    	freopen("peach.out","w",stdout);
    	cin>>t;
    	while(t--) {
    		cin>>r>>c;
    		for(int i=1; i<=r; i++) {
    			for(int j=1; j<=c; j++) {
    				cin>>a[i][j];
    			}
    		}
    		for(int i=1; i<=r; i++) {
    			for(int j=1; j<=c; j++) {
    				a[i][j]+=max(a[i-1][j],a[i][j-1]);//At this time, use the backward method. Because there are only two directions to get to this point:
    			}
    		}
    		cout<<a[r][c]<<endl;//One is on the left and the other is on the top. The point where the accumulated number is larger is from which point.
    	}
    	return 0;
    }
    
  • 相关阅读:
    判断arm立即数是否合法的小程序
    一个操作系统的实现:关于ALIGN的若干解释
    一个郁闷的C语言小问题
    test
    浮点数的比较
    一个操作系统的实现:Descriptor 3详解
    一个操作系统的实现:关于CPL、RPL、DPL
    C99可变长数组VLA详解
    SVProgressHUD 用法
    IOS CALayer 详解
  • 原文地址:https://www.cnblogs.com/jiupinzhimaguan/p/13805959.html
Copyright © 2011-2022 走看看