当前位置:网站首页>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日
边栏推荐
- Refined operation, extending the full life cycle value LTV
- Spark-day02-core programming-rdd
- Laravel+gatewayworker completes the im instant messaging and file transfer functions (Chapter 4: server debugging errors)
- Introduction to the strongest swarm cluster one click deployment + hydrogen bomb level container management tool
- 证券账户可以开通 开户安全吗
- PHP get directory size
- Analysis report on the "fourteenth five year plan" and investment prospect of China's pharmaceutical equipment industry 2022-2028
- Oracle锁表查询和解锁方法
- PolarisMesh系列文章——概念系列(一)
- PHP uses laravel pay component to quickly access wechat jsapi payment (wechat official account payment)
猜你喜欢
PHP uses laravel pay component to quickly access wechat jsapi payment (wechat official account payment)
【概率论】条件概率、贝叶斯公式、相关系数、中心极限定理、参数估计、假设检验
The loss of female scientists
1、 MySQL introduction
Laravel subdomain accesses different routing files and different modules
TSMC Samsung will mass produce 3nm chips in 2022: will the iPhone be the first?
Introduction to the four major FPGA manufacturers abroad
Scala-day06- pattern matching - Generic
[solved] data duplication or data loss after laravel paginate() paging
女性科学家的流失
随机推荐
PHP laravel+gatewayworker completes im instant messaging and file transfer functions (Chapter 2: explanation of business logic)
HUST network attack and defense practice | 6_ IOT device firmware security experiment | Experiment 2 MPU based IOT device attack mitigation technology
SQL injection
Php+laravel5.7 use Alibaba oss+ Alibaba media to process and upload image / video files
Build document editor based on slate
Analysis report on the "fourteenth five year plan" and investment prospect of China's pharmaceutical equipment industry 2022-2028
I'd like to know what preferential activities are available for stock account opening? Is it safe to open an account online?
【毕业季·进击的技术er】忆毕业一年有感
Xiaolong 888 was released, Xiaomi 11 was launched, and 14 manufacturers carried it in the first batch!
汇编语言(7)运算指令
PHP unit conversion
Five problems and solutions of member operation
Is it safe to open a securities account
PHP generate order number
Investment forecast and development strategy analysis report of China's rural sewage treatment industry in 2022
2022 edition of China's cotton chemical fiber printing and dyeing Market Status Investigation and Prospect Forecast Analysis Report
Realize microservice load balancing (ribbon)
webgame开发中的文件解密
Scala-day03- operators and loop control
PHP uses laravel pay component to quickly access wechat jsapi payment (wechat official account payment)