当前位置:网站首页>-采花生-
-采花生-
2022-08-09 23:46:00 【-JMY-】
题目描述
在参加“采花生”这个项目比赛时,考官会出示一块n行、m列的花生田,上面一共种了n*m株花生苗。每株花生植株下都结了一定数量的花生果,比赛开始时选手站在第1行,第1列的位置,现要求用最短的时间找到结花生果最多的一株花生植株(数据保证花生果最多的植株只有一株),然后按先向南(下)走,再向东(右)的路线顺序去采摘它的花生果,沿路经过的其他花生植株下面的花生果也要一并采摘下来,但不允许采摘没有路过的花生植株,否则依犯规出局处理。问这个选手一共可以采摘到多少粒花生果?
如一块n=5,m=6的花生田
第1列 第2列 第3列 第4列 第5列 第6列
第1行 5 7 4 5 1 13
第2行 9 6 3 2 8 7
第3行 10 14 0 1 9 4
第4行 4 6 9 18 25 0
第5行 3 1 2 9 0 2
可以发现结花生果最多的那株花生植株在(4,5),则选手采摘的顺序应为(1,1)-(2,1)-(3,1)-(4,1)-(4,2)-(4,3)-(4,4)-(4,5),一共采得的花生果粒数为5+9+10+4+6+9+18+25=86。
输入
第1行有两个整数n和m( 1 < n,m <= 100 ),表示花生田一共有n行m列。
第2至n+1行,每行有m个用空格隔开的整数,第i + 1行的第j个整数Pij(0 <= Pij <= 700)表示花生田里植株(i, j)下花生的数目,0表示该植株下没有花生。
输出
只有一行,一个整数,表示选手一共摘到的花生果数目。
样例输入
5 6 5 7 4 5 1 13 9 6 3 2 8 7 10 14 0 1 9 4 4 6 9 18 25 0 3 1 2 9 0 2
样例输出
86
参考代码:
#include<bits/stdc++.h>
using namespace std;
int n,m,a[105][105],x,y,s,maxn;
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
scanf("%d",&a[i][j]);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(a[i][j]>maxn){
maxn=a[i][j];
x=j+1;
y=i+1;
}
for(int i=0;i<y;i++)
s+=a[i][0];
for(int i=1;i<x;i++)
s+=a[y-1][i];
printf("%d",s);
return 0;
}
边栏推荐
猜你喜欢
365天挑战LeetCode1000题——Day 052 逐步求和得到正数的最小值 贪心
labelme标注的json标签转txt格式
MATLB|And her ups and downs and finally reached the peak of life [Romantic Journey]
openEuler 知:abi 检测
go语言的并发原理(goroutine)
上交所实时行情文件汇总
Alibaba Cloud SMS Service Activation
深入理解Aarch64内存管理
有PEG-Biotin参与的(CAS:1778736-18-7)Biotin-PEG4-OH广泛用于分子靶点检测
02|运算符
随机推荐
【Infiltration tool】Browser data export tool
基于FPGA的任意字节数的串口接收(含源码工程)
WPF DataGrid using data templates
2022金九银十工作潮,怎么样才能成功跳槽面试拿到高薪呢?
CAS:183896-00-6 (Biotin-PEG3-C3-NH2) PEG衍生物
断开和服务器共享连接的方法「建议收藏」
MATLB|And her ups and downs and finally reached the peak of life [Romantic Journey]
Distributed database problem (3): data consistency
c语言结构体、函数以及指针练习(简单通讯录)
【CAS:41994-02-9 |Biotinyl tyramide】生物素基酪氨酰胺价格
RebatMq消息中间件(一) 各个中间件介绍
Leetcode81. 搜索旋转排序数组 II
【剑指offer】第一题 第二题
由生物素参与的D-Biotinol,CAS号:53906-36-8具体特性说明
NotWritableError: The current user does not have write permissions when conda creates a new environment
dlopen failed: library “libtaml.so“ not found
《痞子衡嵌入式半月刊》 第 60 期
deepstream学习笔记(三):deepstream-imagedata-multistream解析与接入适配yolov5模型测试
hql语言
错误提示:Syntax error on token “function”, delete this token