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.

Sample1

Input

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

Output

8
16

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;
}

Eating Peach (peach)的更多相关文章

  1. Peach+Fuzzer

    目录 1 Peach是什么....................................................................................... ...

  2. 东大OJ-1544: GG的战争法则

    题目描述 你在桥上看风景 看风景的人在楼上看你 明月装饰了你的窗子 你装饰了我的梦 这是GG在长坂坡发出的感叹. 三年前GG莫名的穿越到了三国时期,在这三年里他看尽了各种杀戮,心里早已麻木.GG他渴望 ...

  3. Java基础算法集50题

    最近因为要准备实习,还有一个蓝桥杯的编程比赛,所以准备加强一下算法这块,然后百度了一下java基础算法,看到的都是那50套题,那就花了差不多三个晚自习的时间吧,大体看了一遍,做了其中的27道题,有一些 ...

  4. go编程之常见工具函数

    1.时间格式化 基于模式的布局进行时间格式化和解析 package main import "fmt" import "time" func main() { ...

  5. 【JavaScript for循环实例】

    1.大马驮2石粮食,中马驮1石粮食,两头小马驮一石粮食,要用100匹马,驮100石粮食,该如何调配? //驮100石粮食,大马需要50匹 for(var a=0;a<=50;a++){ //驮1 ...

  6. JS for循环 if判断、white循环。小练习二

    假设一个简单的ATM机的取款过程是这样的:首先提示用户输入密码(password),最多只能输入三次,超过3次则提示用户“密码错误,请取卡”结束交易.如果用户密码正确,再提示用户输入取款金额(amou ...

  7. Java8分组(groupingBy)

    1.分组,计数,排序 public class Java8Example1 { public static void main(String[] args) { List<String> ...

  8. Pronunciation Guide for 25 Common Fruits

    Pronunciation Guide for 25 Common Fruits Share Tweet Share Tagged With: Vocabulary Words Know how to ...

  9. ref:一系列用于Fuzzing学习的资源汇总

    ref:http://www.freebuf.com/articles/rookie/169413.html 一系列用于Fuzzing学习的资源汇总 secist2018-04-30共185833人围 ...

随机推荐

  1. Dungeon Master(三维bfs)

    You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...

  2. 转载:Oracle常见字段类型

    转载节选自:https://bbs.csdn.net/topics/220059184 数据类型 参数 描述 char(n) n=1 to 2000字节 定长字符串,n字节长,如果不指定长度,缺省为1 ...

  3. Java得到指定日期的时间

    //得到指定日期(几天前/几天后)整数往后推,负数往前移动private Date getAppointDay(int num) throws ParseException { DateFormat ...

  4. 重学Ajax

    什么是Ajax Asynchronous JavaScript and xml 异步的JavaScript和XML 只是一种js的应用,在无需重新加载整个网页的情况下实现部分网页的数据更新的技术.减少 ...

  5. html基础:DOM操作

    DOM(Document Object Model 文档对象模型) 一个web页面被封装成一个dom对象,通过dom中的js对页面的标签进行操作 一.获取对象 浏览器页面上右键--检查--consol ...

  6. 15个随机图片API

    15个随机图片API 妈妈再也不用担心我网站没图用了呜 请不要重复刷新此页面 ! 找了很久的说,你难道不想收藏一下吗 其中有些 API 速度并不太好,可能会拖慢贵站的速度 我也不能保证这些 API 能 ...

  7. python中的n次方表示法 **n

    例题:计算2的n次方,n由用户输入(N次方用**表示)# n=eval(input('手动输入n的值:')) #个人感觉,不确定是int还是float时,用eval来表示,eval后面接表达式# pr ...

  8. [LeetCode]26. 删除排序数组中的重复项(数组,双指针)

    题目 给定一个排序数组,你需要在 原地 删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度. 不要使用额外的数组空间,你必须在 原地 修改输入数组 并在使用 O(1) 额外空间的条件下 ...

  9. Java成神之路:第二帖---- 数据结构与算法之稀疏数组

    数据结构与算法--稀疏数组 转换方法 记录数组有几行几列,有多少个不同的值 把不同的值的元素的行列,记录在一个小规模的数组中,以此来缩小数组的规模 如图: 二维数组转稀疏数组 对原始的二维数组进行遍历 ...

  10. JavaScript闭包函数的理解

    闭包就是一个函数能够访问其函数外部作用域中的变量,即在外面可以调用函数中的函数的变量,其实他就是将函数内外部连接起来的桥梁 闭包三大特点: 1. 函数嵌套函数 2. 内部函数可以访问外部函数的变量 3 ...