当前位置:网站首页>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
边栏推荐
- What features are added to Photoshop 2022 23.4.1? Do you know anything
- Analysis and protection of heart blood dripping vulnerability (cve-2014-0160)
- Mysql database explanation (6)
- Beifu twincat3 can read and write CSV and txt files
- MariaDB study notes
- Update and download of Beifu EtherCAT XML description file
- Design of simple digital circuit traffic light
- Arcpy - - utilisation de la fonction insertlayer (): ajout de calques dans un document de carte
- What are the common categories of software testing?
- Beifu PLC realizes data power-off maintenance based on cx5130
猜你喜欢

First pass! Baidu AI Cloud Xiling platform has obtained the authoritative certification of digital human ability evaluation from the Institute of information technology

MediaPipe手势(Hands)

Explain C language 11 in detail (C language series)

C language: Exercise 2

ES6 module

Machine learning notes - seasonality of time series

Composite mode

5月产品升级观察站

Beifu realizes the control of time slice size and quantity through CTU and ton

Processsing function random
随机推荐
Bigint: handles large numbers (integers of any length)
Beifu cx5130 card replacement and transfer of existing authorization files
12 SQL optimization schemes summarized by old drivers (very practical)
Beifu realizes the control of time slice size and quantity through CTU and ton
MySQL讲解(二)
Aesthetic experience (episode 238) Luo Guozheng
Mysql database explanation (III)
E - Apple Catching
5月产品升级观察站
Coprime and non coprime of template problems of Chinese remainder theorem
Mysql database explanation (IV)
Electron official docs series: Best Practices
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
B - Bridging signals
Dark horse notes - Common APIs
J - Wooden Sticks poj 1065
Script - crawl the customized storage path of the cartoon and download it to the local
防火墙介绍
解中小企业之困,百度智能云打个样