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. 被Spring坑了一把,查看源码终于解决了DataFlow部署K8s应用的问题

    1 前言 欢迎访问南瓜慢说 www.pkslow.com获取更多精彩文章! Docker & Kubernetes相关文章:容器技术 基于各种原因,团队的Kubernetes被加了限制,必须在 ...

  2. 想要使用GPU进行加速?那你必须事先了解CUDA和cuDNN

    这一期我们来介绍如何在Windows上安装CUDA,使得对图像数据处理的速度大大加快,在正式的下载与安装之前,首先一起学习一下预导知识,让大家知道为什么使用GPU可以加速对图像的处理和计算,以及自己的 ...

  3. shell小技巧(1)计算一个文件中空行数量

    方法1: grep -E "^$" 1.txt | wc -l 详解:在网上摘抄,个人觉得不使用-E参数也行,利用正则^$可帅选出空行 方法2: file="1.txt& ...

  4. 如何在本机启动两个tomcat

    Tomcat下载地址:http://ftp.kddilabs.jp/infosystems/apache/tomcat/tomcat-9/v9.0.30/bin/apache-tomcat-9.0.3 ...

  5. JQuery的Ajax实现注册检测用户名

    Ajax(无需等待直接向服务器发起请求) (Asynchronous Javascript And Xml) :异步的 Google创新的一种js技术 实现方法一:比较原始没有封装的方法: //核对用 ...

  6. SQL用于更新ID为顺序ID(用于删除了几条数据导致id不连续)

    UPDATE tab1022zhm SET ID =FROM (SELECT ROW_NUMBER() OVER (ORDER BY id) ROW,comName FROM dbo.tab1022z ...

  7. 【NOIP2015模拟】终章-剑之魂

    背景介绍 古堡,暗鸦,斜阳,和深渊-- 等了三年,我独自一人,终于来到了这里-- "终焉的试炼吗?就在这里吗?"我自言自语道. "终焉的试炼啊!就在这里啊!"我 ...

  8. 【新阁教育】基于EtherNet/IP实现欧姆龙NX系列PLC通信

    1.引言 工业以太网协议 (Ethernet/IP) 是由ODVA所开发并得到了罗克韦尔自动化的强大支持.它使用已用于ControlNet和DeviceNet的控制和信息协议 (CIP) 为应用层协议 ...

  9. Win10 在VM里面装Centos7.4后使用桥接模式连接外网,并用MobaXterm远程虚拟机详细教程

    1.首先登陆虚拟机如图 2.执行ping命令看虚拟机里面的centos7是否可以连网 ping www.baiducom 此时会报错:name or service not known 3.设置一个文 ...

  10. [LeetCode]394. 字符串解码(栈)

    题目 给定一个经过编码的字符串,返回它解码后的字符串. 编码规则为: k[encoded_string],表示其中方括号内部的 encoded_string 正好重复 k 次.注意 k 保证为正整数. ...