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

最新文章

  1. IOS 网络浅析-(十一 三方 AFNetworking3.0简介)
  2. Linq to Xml读取复杂xml(带命名空间)
  3. 谷歌浏览器 查看源码里的a:hover CSS样式 还有火狐的查看方式
  4. WPF中图形表示语法详解(Path之Data属性语法)ZZ
  5. BZOJ1022 [SHOI2008]小约翰的游戏John
  6. OpenCV(5)-图像掩码操作(卷积)-锐化
  7. linux杂记(二)主机硬盘规划
  8. Hibernate4 占位符(?)
  9. a:link visited hover active
  10. www.netcraft.com查看站点服务器使用的是什么操作系统
  11. [Swift]LeetCode745. 前缀和后缀搜索 | Prefix and Suffix Search
  12. javascript中的立即执行函数的原理
  13. python的内置函数time
  14. springmvc的异步处理
  15. Java NIO -- 阻塞和非阻塞
  16. 两场CF
  17. 在dosbox窗口显示a~z
  18. Java的4种保留4位小数的方法(转)
  19. Xcode 8 的 Debug 新特性 —- WWDC 2016 Session 410 &amp; 412 学习笔记
  20. 关于PyCharm database查看db.sqlites文件无内容的一种可能解决方法

热门文章

  1. 深度学习论文翻译解析(十三):Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks
  2. Docker 容器编排利器 Docker Compose
  3. Python学习—Anaconda详细 下载、安装与使用,以及如何创建虚拟环境,不仅仅只有安装步骤哦
  4. 求支付表中按id累积和最接近100的那条记录
  5. 20190928-02使用Redis客户端Jedis连接Redis,以及用Java代码操作Redis 000 030
  6. leetcode刷题-51N皇后
  7. ui自动化--鼠标操作ActionChains
  8. Java面试炼金系列 (1) | 关于String类的常见面试题剖析
  9. 《Head First 设计模式》:组合模式
  10. [LeetCode] 46. 全排列(回溯)