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.
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)的更多相关文章
- Peach+Fuzzer
目录 1 Peach是什么....................................................................................... ...
- 东大OJ-1544: GG的战争法则
题目描述 你在桥上看风景 看风景的人在楼上看你 明月装饰了你的窗子 你装饰了我的梦 这是GG在长坂坡发出的感叹. 三年前GG莫名的穿越到了三国时期,在这三年里他看尽了各种杀戮,心里早已麻木.GG他渴望 ...
- Java基础算法集50题
最近因为要准备实习,还有一个蓝桥杯的编程比赛,所以准备加强一下算法这块,然后百度了一下java基础算法,看到的都是那50套题,那就花了差不多三个晚自习的时间吧,大体看了一遍,做了其中的27道题,有一些 ...
- go编程之常见工具函数
1.时间格式化 基于模式的布局进行时间格式化和解析 package main import "fmt" import "time" func main() { ...
- 【JavaScript for循环实例】
1.大马驮2石粮食,中马驮1石粮食,两头小马驮一石粮食,要用100匹马,驮100石粮食,该如何调配? //驮100石粮食,大马需要50匹 for(var a=0;a<=50;a++){ //驮1 ...
- JS for循环 if判断、white循环。小练习二
假设一个简单的ATM机的取款过程是这样的:首先提示用户输入密码(password),最多只能输入三次,超过3次则提示用户“密码错误,请取卡”结束交易.如果用户密码正确,再提示用户输入取款金额(amou ...
- Java8分组(groupingBy)
1.分组,计数,排序 public class Java8Example1 { public static void main(String[] args) { List<String> ...
- Pronunciation Guide for 25 Common Fruits
Pronunciation Guide for 25 Common Fruits Share Tweet Share Tagged With: Vocabulary Words Know how to ...
- ref:一系列用于Fuzzing学习的资源汇总
ref:http://www.freebuf.com/articles/rookie/169413.html 一系列用于Fuzzing学习的资源汇总 secist2018-04-30共185833人围 ...
随机推荐
- AcWing 285. 没有上司的舞会(树形dp入门)
Ural大学有N名职员,编号为1~N. 他们的关系就像一棵以校长为根的树,父节点就是子节点的直接上司. 每个职员有一个快乐指数,用整数 HiHi 给出,其中 1≤i≤N1≤i≤N. 现在要召开一场周年 ...
- oracle修改管理员密码
运行到C盘根目录 2.输入:SET ORACLE_SID = 你的SID名称 3.输入:sqlplus/nolog 4.输入:connect/as sysdba 5.输入:altre user ris ...
- MySQL索引凭什么能让查询效率提高这么多?
点赞再看,养成习惯,微信搜一搜[三太子敖丙]关注这个喜欢写情怀的程序员. 本文 GitHub https://github.com/JavaFamily 已收录,有一线大厂面试完整考点.资料以及我的系 ...
- KMP记录
例题:luogu P3375 [模板]KMP字符串匹配 知识点:1.KMP模板,熟悉KMP 2.理解KMP过程:失配时,是从后缀转向前缀.即失配时,匹配串是从尾转到头继续匹配,被匹配串不改变. 3.注 ...
- selenium+python3+pycharm
当使用selenium实现元素定位时,运行: 元素定位,常用8大方法.具体百度 在此以id定位进行解释 #from selenium import webdriver # driver=webdriv ...
- 跟我一起学.NetCore之文件系统应用及核心浅析
前言 在开发过程中,肯定避免不了读取文件操作,比如读取配置文件.上传和下载文件.Web中html.js.css.图片等静态资源的访问:在配置文件读取章节中有说到,针对不同配置源数据读取由对应的ICon ...
- oracle数据处理之sql*loader(一)
SQL*Loader是oracle提供的可以从多种平面文件中向数据库中加载数据的工具,它比较适合业务分析类型数据库(数据仓库);使用sqlldr工具可以在很短的时间内向数据库中加载大量的数据,像把制作 ...
- python3 while循环
python不支持n++这样格式,因为python中变量不像c那样事先定义好变量类型,在内存中开辟指定的空间,然后赋值. python中以字符串为例,事先在内存划分空间来存放字符串,然后用变量名来指向 ...
- [LeetCode]1083. 销售分析 II(Mysql,having+if)
题目 编写一个 SQL 查询,查询购买了 S8 手机却没有购买 iPhone 的买家. 题解 使用having + sum+if,而不是自查询. 代码 # Write your MySQL query ...
- [LeetCode]15. 三数之和(数组)(双指针)
题目 给定一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?找出所有满足条件且不重复的三元组. 注意:答案中不可以包含重复的三 ...