当前位置:网站首页>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
边栏推荐
- scrapy——爬取漫画自定义存储路径下载到本地
- Analysis and protection of heart blood dripping vulnerability (cve-2014-0160)
- Mysql database explanation (V)
- 8. [STM32] timer (TIM) -- interrupt, PWM, input capture experiment (proficient in timer)
- System tasks (display / print class) in Verilog - $display, $write, $strobe, $monitor
- awk工具
- C - Common Subsequence
- 享元模式(Flyweight)
- MariaDB study notes
- 外观模式(Facade)
猜你喜欢

Decorator

Chapter 01_ Installation and use of MySQL under Linux

To solve the difficulties of small and medium-sized enterprises, Baidu AI Cloud makes an example

Chapter 10 setting up structured logging (2)

Processsing mouse interactive learning
What should the software test report include? Interview must ask

Bigint: handles large numbers (integers of any length)

MySQL讲解(二)

mariadb学习笔记

Update and download of Beifu EtherCAT XML description file
随机推荐
Map value
May product upgrade observation station
SQL assigns the field value of data table B to a column in data table a
Echart stack histogram: add white spacing effect setting between color blocks
J - Wooden Sticks poj 1065
MySQL数据库讲解(三)
Electron official docs series: Best Practices
Uva10341 solve it
Fire warning is completed within 10 seconds, and Baidu AI Cloud helps Kunming Guandu build a new benchmark of smart city
[how to connect the network] Chapter 2 (next): receiving a network packet
MySQL数据库讲解(五)
Beifu realizes the control of time slice size and quantity through CTU and ton
Oplg: new generation cloud native observable best practices
Digital signal processing -- Design of linear phase type (Ⅰ, Ⅲ) FIR filter (1)
Arcpy - - utilisation de la fonction insertlayer (): ajout de calques dans un document de carte
8、【STM32】定时器(TIM)——中断、PWM、输入捕获实验(一文精通定时器)
MySQL explanation (II)
Composite mode
IDC report: the AI cloud market share of Baidu AI Cloud ranks first for six consecutive times
UVA5009 Error Curves三分