当前位置:网站首页>7-2 摘花生
7-2 摘花生
2022-06-26 12:32:00 【白—】
7-2 摘花生
Hello Kitty想摘点花生送给她喜欢的米老鼠。
她来到一片有网格状道路的矩形花生地(如下图),从西北角进去,东南角出来。
地里每个道路的交叉点上都有种着一株花生苗,上面有若干颗花生,经过一株花生苗就能摘走该它上面所有的花生。
Hello Kitty只能向东或向南走,不能向西或向北走。
问Hello Kitty最多能够摘到多少颗花生。
输入格式
第一行是一个整数T,代表一共有多少组数据。
接下来是T组数据。
每组数据的第一行是两个整数,分别代表花生苗的行数R和列数 C。
每组数据的接下来R行数据,从北向南依次描述每行花生苗的情况。每行数据有C个整数,按从西向东的顺序描述了该行每株花生苗上的花生数目M。
1≤T≤100,
1≤R,C≤100,
0≤M≤1000
输出格式
对每组输入数据,输出一行,内容为Hello Kitty能摘到得最多的花生颗数。
输入样例:
在这里给出一组输入。例如:
2
2 2
1 1
3 4
2 3
2 3 4
1 6 5
输出样例:
在这里给出相应的输出。例如:
8
16
代码:
#include<stdio.h>
int t,m,n;
int a[1010][1010];
int vis[1010][1010];
int max(int a,int b)
{
return a>=b?a:b;
}
int find(int y,int x)
{
if(x>n||y>m)
return 0;
if(vis[y][x]!=-1)
return vis[y][x];
if(y==m&&x<=n)
return find(y,x+1)+a[y][x];
else if(y<=m&&x==n)
return find(y+1,x)+a[y][x];
else if(y<=m&&x<=n)
{
int l=find(y,x+1)+a[y][x];
int r=find(y+1,x)+a[y][x];
return vis[y][x]=max(l,r);
}
}
int main()
{
scanf("%d",&t);
for(int i=0;i<t;i++)
{
scanf("%d%d",&m,&n);
memset(a,-1,sizeof(a));
memset(vis,-1,sizeof(vis));
for(int j=1;j<=m;j++)
for(int k=1;k<=n;k++)
scanf("%d",&a[j][k]);
printf("%d\n",find(1,1));
}
}
202206260903日
边栏推荐
- PHP uses laravel pay component to quickly access wechat jsapi payment (wechat official account payment)
- Hello! Forward proxy!
- What should I do from member labels to portraits?
- How do consumer goods enterprises formulate membership interests?
- Scala-day06- pattern matching - Generic
- Question B of 2016 Sichuan Ti Cup Electronic Design Competition
- Member system + enterprise wechat + applet to help the efficient transformation of private domain
- What are the top ten securities companies? Is it safe to open a mobile account?
- Comparison of latest mobile phone processors in 2020 (with mobile phone CPU ladder diagram)
- China's smart toy market outlook and investment strategy consulting forecast report from 2022 to 2027
猜你喜欢

Vscode solves the problem of Chinese garbled code

MySQL optimization - index (what is an index?)

Mysql8 master-slave replication

Comparison of latest mobile phone processors in 2020 (with mobile phone CPU ladder diagram)

Laravel subdomain accesses different routing files and different modules

4. N queen problem

International beauty industry giants bet on China
女性科学家的流失

Ctrip ticket app KMM cross end kV repository mmkv kotlin | open source

"Pinduoduo and short video speed version", how can I roast!
随机推荐
MOS管基本原理,单片机重要知识点
This executeQuery (SQL) cannot compile classes for JSP. What is the reason?
One click deployment CEPH script
PHP returns false when calling redis method decrby less than 0
dried food! Yiwen will show you SD card, TF card and SIM card!
1、 MySQL introduction
Function collapse and expansion shortcut keys in vscode (latest and correct)
Introduction to the strongest swarm cluster one click deployment + hydrogen bomb level container management tool
Ad - update the modified PCB package to the current PCB
Report on in-depth analysis and investment strategy recommendations for China's petroleum coke industry (2022 Edition)
UDP协议详解[通俗易懂]
The most complete kubernetes core command of the latest version so far
环形队列php
Spark-day02-core programming-rdd
2022 edition of Beijing 5g industry investment planning and development prospect forecast analysis report
Using the methods in the repository to solve practical problems
International beauty industry giants bet on China
Vscode solves the problem of Chinese garbled code
New routing file in laravel framework
菜鸟实战UML——活动图