当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

ASP. NET CORE Study03

ASP.NET CORE Study01

ASP. NET CORE Study08

MySQ 8.0 推出直方图,性能大大提升!

The white paper on the panorama of the digital economy and the digitalization of consumer finance were released

在线JSON转PlainText工具

Implementation of fruit and vegetable mall management system based on SSM

ASP.NET CORE Study09

pytorch基础

ASP. NET CORE Study02
随机推荐
ASP. NET CORE Study06
我的NVIDIA开发者之旅-Jetson Nano 2gb教你怎么训练模型(完整的模型训练套路)
ASP. NET CORE Study05
性能测试-01-简介
Performance test-01-introduction
I²C、SMBus、PMBus关系
关于IP定位查询接口的测评Ⅰ
Deep understanding of Bayes theorem
Why does CAD export PDF have no color
The white paper on the panorama of the digital economy and the digitalization of consumer finance were released
Vs2012 VC creates a new blank window application
Finereport installation tutorial
Realization of a springboard machine
从pdb源码到frame帧对象
为什么CAD导出PDF没有颜色
Understand leveldb write operation
最新!基于Open3D的点云处理入门与实战教程
ASP.NET CORE Study07
SHAREit实力出众,登陆全球 IAP 实力榜 Top7
SHAREit實力出眾,登陸全球 IAP 實力榜 Top7