当前位置:网站首页>1015.摘花生
1015.摘花生
2022-06-28 12:55:00 【HHppGo】
题目:
Hello Kitty想摘点花生送给她喜欢的米老鼠。
她来到一片有网格状道路的矩形花生地(如下图),从西北角进去,东南角出来。
地里每个道路的交叉点上都有种着一株花生苗,上面有若干颗花生,经过一株花生苗就能摘走该它上面所有的花生。
Hello Kitty只能向东或向南走,不能向西或向北走。
问Hello Kitty最多能够摘到多少颗花生。
输入格式:
第一行是一个整数T,代表一共有多少组数据。
接下来是T组数据。
每组数据的第一行是两个整数,分别代表花生苗的行数R和列数 C。
每组数据的接下来R行数据,从北向南依次描述每行花生苗的情况。每行数据有C个整数,按从西向东的顺序描述了该行每株花生苗上的花生数目M。
输出格式:
对每组输入数据,输出一行,内容为Hello Kitty能摘到得最多的花生颗数。
数据范围:

输入样例:
2
2 2
1 1
3 4
2 3
2 3 4
1 6 5
输出样例:
8
16
思路:

AC代码:
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const int N = 110;
int n,m;
int w[N][N];
int f[N][N];
int t;
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(int i = 1;i<=n;i++)
for(int j = 1;j<=m;j++)
{
scanf("%d",&w[i][j]);
}
for(int i = 1;i<=n;i++)
for(int j = 1;j<=m;j++)
{
f[i][j] = max(f[i-1][j],f[i][j-1]) + w[i][j];
}
printf("%d\n",f[n][m]);
}
return 0;
}
边栏推荐
- From simplekv to redis
- JS duration and asynchronous function promise
- [cloud native] can self-service reports and Bi do so many things?
- 数字孪生能源系统,打造低碳时代“透视”眼
- ASP. NET CORE Study04
- Unity Editor Extension Foundation, GUI
- Manjaro easyconnecy error: libgtk-x11-2.0 so. 0: cannot open shared object file: No such file or directory
- centos6.5 php+mysql mysql库找不到
- 华泰证券手机app下载 怎么办理开户最安全
- pytorch模型
猜你喜欢

一文抄 10 篇!韩国发表的顶级会议论文被曝抄袭,第一作者是“原罪”?

腾讯确认QQ大规模盗号,iPhone14无缘Type-C,第四大运营商5G正式放号,今日更多大新闻在此...

Vs2012 VC creates a new blank window application

Unity Editor Extension Foundation, GUI

Flink stream processing API collection: master all Flink stream processing technologies. Just read this article

高考失利进哈工大,毕业却留校要当“探索者”,丁效:科研就是厚积薄发

Mathematical principle derivation of structured light phase shift method + multifrequency heterodyne

Go语学习笔记 - gorm使用 - 数据库配置、表新增 | Web框架Gin(七)

Online JSON to plaintext tool

Implementation of fruit and vegetable mall management system based on SSM
随机推荐
数字孪生能源系统,打造低碳时代“透视”眼
基础软件照搬开源不可取,自力更生才是正途
From jsonpath and XPath to spl
ASP.NET CORE Study06
Validateur async. Vérificateur de données JS
UDP RTP packet frame loss
嵌入式开发:估算电池寿命的7个技巧
Enterprise source code confidentiality scheme sharing
Jerry's wif interferes with Bluetooth [chapter]
centos6.5 php+mysql mysql库找不到
Hundreds of lines of code to implement a JSON parser
My NVIDIA developer tour -jetson nano 2GB teaches you how to train models (complete model training routines)
华泰证券手机app下载 怎么办理开户最安全
Summary of 2022 China Merchants fintech competition
scratch旅行相册 电子学会图形化编程scratch等级考试一级真题和答案解析2022年6月
ASP.NET CORE Study11
在线JSON转PlainText工具
ASP. NET CORE Study09
Bytev builds a dynamic digital twin network security platform -- helping network security development
From simplekv to redis