当前位置:网站首页>7-2 picking peanuts
7-2 picking peanuts
2022-06-26 13:21:00 【White -】
7-2 Picking flowers
Hello Kitty I want to pick some peanuts for her favorite Mickey Mouse .
She came to a rectangular peanut field with a grid of roads ( Here's the picture ), Go in from the northwest corner , Come out from the southeast corner .
There is a peanut seedling growing at the intersection of every road in the field , There are some peanuts on it , After a peanut seedling, you can pick all the peanuts on it .
Hello Kitty You can only go east or South , You can't go west or North .
ask Hello Kitty How many peanuts can you pick at most .
Input format
The first line is an integer T, Represents how many sets of data there are .
Next is T Group data .
The first row of each set of data is two integers , They represent the rows of peanut seedlings R And number of columns C.
Next for each group of data R Row data , Describe each row of peanut seedlings from north to south . Each row of data has C It's an integer , The number of peanuts per plant in the row is described from west to East M.
1≤T≤100,
1≤R,C≤100,
0≤M≤1000
Output format
Enter data for each group , Output one line , The content is Hello Kitty The number of peanuts that can be picked the most .
sample input :
Here's a set of inputs . for example :
2
2 2
1 1
3 4
2 3
2 3 4
1 6 5
sample output :
Here is the corresponding output . for example :
8
16
Code :
#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 Japan
边栏推荐
- 偶言佳句,孤芳自赏
- Electron official docs series: Get Started
- MySQL explanation (I)
- Beifu cx5130 card replacement and transfer of existing authorization files
- [how to connect the network] Chapter 2 (Part 1): establish a connection, transmit data, and disconnect
- Vivado error code [drc pdcn-2721] resolution
- Do you know the limitations of automated testing?
- What should the software test report include? Interview must ask
- ES6:Map
- MySQL讲解(二)
猜你喜欢
![Vivado error code [drc pdcn-2721] resolution](/img/de/ce1a72f072254ae227fdcb307641a2.png)
Vivado error code [drc pdcn-2721] resolution

Common faults of MySQL database - forgetting database password

Arcpy -- use of insertlayer() function: adding layers to map documents

MySQL数据库讲解(三)

Processing random generation line animation

Explain C language 11 in detail (C language series)

外观模式(Facade)

What features are added to Photoshop 2022 23.4.1? Do you know anything

Learn how to develop owl components by hand (7): practical use of owl projects

Do you know the limitations of automated testing?
随机推荐
解中小企业之困,百度智能云打个样
I have a good word to say, and I admire myself
Mysql database explanation (III)
Processing function translate (mousex, mousey) learning
System tasks (display / print class) in Verilog - $display, $write, $strobe, $monitor
Design of simple digital circuit traffic light
Uva5009 error curves three points
中国剩余定理模板题 互质与非互质
Electron official docs series: Best Practices
Beifu PLC realizes zero point power-off hold of absolute value encoder -- use of bias
G - Cow Bowling
Beifu PLC based on NT_ Shutdown to realize automatic shutdown and restart of controller
装饰器(Decorator)
May product upgrade observation station
Summary of wechat applet test points
Bifu divides EtherCAT module into multiple synchronization units for operation -- use of sync units
Electron official docs series: Processes in Electron
Electron official docs series: Development
Chapter 01_ Installation and use of MySQL under Linux
Processing polyhedron change