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人围 ...
随机推荐
- Queries for Number of Palindromes(区间dp)
You've got a string s = s1s2... s|s| of length |s|, consisting of lowercase English letters. There a ...
- 面试【JAVA基础】多线程
本次整理的内容如下: 1.进程与线程的区别 进程是一个可执行的程序,是系统资源分配的基本单位:线程是进程内相对独立的可执行单元,是操作系统进行任务调度的基本单位. 2.进程间的通信方式 2.1.操作系 ...
- 解放生产力:Spring Boot的注解校验
关于对象入参的校验,我们可能第一个想到的就是在Controller层或者Service层增加很多if else的判断,如: if (user.getPassword() == "" ...
- 小程序开发-开发模式下关闭http域名校验
小程序开发模式去掉域名校验 我们在开发小程序的时候如果用到其他网络地址,在小程序运行时调试器会输出 : http://www.example.com 不在以下 request 合法域名列表中,请参考文 ...
- indexOf原理,Java,javascript,python实现
简介 最近做项目的时候,发现无论是前端还是后端,indexOf出现的概率都非常频繁,今天我们来看下他的实现原理吧! indexOf的含义:给定一个字符串去匹配另一个字符串的下标,如果匹配到,返回下 ...
- 《闲扯Redis十一》Redis 有序集合对象底层实现
一.前言 Redis 提供了5种数据类型:String(字符串).Hash(哈希).List(列表).Set(集合).Zset(有序集合),理解每种数据类型的特点对于redis的开发和运维非常重要. ...
- (高难度SQL)从产品表中找出相同前缀 (都云作者痴 谁解其中味)
--期盼值 找出AA,3;PDST,3;QPL-,3;TP-,2; --基本表 create table tb_product( id number(9,0) primary key, name nv ...
- 20190928-02使用Redis客户端Jedis连接Redis,以及用Java代码操作Redis 000 030
启动redis package com.yujie.jedis; import java.util.HashMap; import java.util.Map; import java.util.Se ...
- 关于跨域策略文件crossdomain.xml文件
下载flexpaper源码修改后做成swf阅读器,要加入待阅读的swf文件,可以在flex里调用js的方法来获取swf文件的路径的方法,在js只专注获取路径就行,等着flex来调用:但这里会遇到一个问 ...
- [LeetCode] 79. 单词搜索(DFS,回溯)
题目 给定一个二维网格和一个单词,找出该单词是否存在于网格中. 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中"相邻"单元格是那些水平相邻或垂直相邻的单元格.同一个单元格 ...