当前位置:网站首页>7-9 treasure hunt route
7-9 treasure hunt route
2022-06-24 23:31:00 【White -】
7-9 Treasure hunt route
In a m That's ok n Column lattice matrix , In each square, there are treasures of different values ( Value can be positive or negative ), What makes Xiao Ming curious is , Of all possible routes from the upper left corner to the lower right corner , What is the maximum total value of the treasure you can find ? And this route to the maximum
How many more ?【 Be careful : You can only go down or right from one grid to the adjacent grid , And the grid baby will be picked up .】
Input format :
The first line is an integer m,n( No more than 100), There will be one at the beginning of the next line m That's ok n An integer matrix of columns , Corresponding to the baby value in the square matrix ( The absolute values of these values do not exceed 500).
Output format :
Output on a single line 2 It's an integer , They are the maximum value of the total value of the treasure that can be found and the number of routes that reach the maximum value ,2 An integer separated by a space .
sample input :
Here's a set of inputs . for example :
4 5
2 -1 6 -2 9
-3 2 5 -5 1
5 8 3 -2 4
5 2 8 -4 7
sample output :
The corresponding output is :
26 3
Code :
#include <stdio.h>
#include <stdlib.h>
int m,n;
int a[110][110];
int times[110][110];
int rem[110][110];
find(x,y)
{
if(x==1&&y==1)
return 0;
else
{
if(x==1)
{
times[x][y]+=times[x][y-1];
return rem[x][y-1];
}
else if(y==1)
{
times[x][y]=times[x-1][y];
return rem[x-1][y];
}
else
{
if(rem[x-1][y]>rem[x][y-1])
{
times[x][y]+=times[x-1][y];
return rem[x-1][y];
}
else if(rem[x-1][y]<rem[x][y-1])
{
times[x][y]+=times[x][y-1];
return rem[x][y-1];
}
else
{
times[x][y]+=times[x-1][y]+times[x][y-1];
return rem[x][y-1];
}
}
}
}
int main()
{
scanf("%d%d",&m,&n);
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
scanf("%d",&a[i][j]);
times[1][1]=1;
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
rem[i][j]=find(i,j)+a[i][j];
printf("%d %d",rem[m][n],times[m][n]);
return 0;
}
202206222109 3、 ... and
边栏推荐
- 22map introduction and API
- Helix distance of point
- R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses exp function and coef function to obtain the corresponding odds rat
- 一文理解OpenStack网络
- 【js】-【树】-学习笔记
- Record the range of data that MySQL update will lock
- R语言使用MatchIt包进行倾向性匹配分析、使用match.data函数构建匹配后的样本集合、通过双样本t检验分析(双独立样本t检验)来判断倾向性评分匹配后样本中的所有协变量的平衡情况
- 7-2 solving the stock buying problem
- R语言使用MatchIt包进行倾向性匹配分析、使用match.data函数构建匹配后的样本集合、对匹配后的样本的不同分组对应的目标变量的均值进行Welch双样本t检验分析、双独立样本t检验
- 7-8 梯云纵
猜你喜欢

Main cause of EMI - mold current

2021-2022中国金融数字化“新”洞察行业研究报告

Simpledateformat concrete classes for formatting and parsing dates

Tomorrow is the PMP Exam (June 25). Have you understood all this?
![[JS] - [tree] - learning notes](/img/62/de4fa2a7c5e52c461b8be4a884a395.png)
[JS] - [tree] - learning notes

点的螺旋距离

Yyds dry goods counting uses xshell to implement agent function

From client to server

Record the range of data that MySQL update will lock
![[JS] - [array, Stack, queue, Link List basis] - Notes](/img/c6/a1bd3b8ef6476d7d549abcb442949a.png)
[JS] - [array, Stack, queue, Link List basis] - Notes
随机推荐
Design and practice of vivo server monitoring architecture
R语言使用glm函数构建泊松对数线性回归模型处理三维列联表数据构建饱和模型、使用summary函数获取模型汇总统计信息、解读模型系数交互作用及其显著性
R语言使用MatchIt包进行倾向性匹配分析、使用match.data函数构建匹配后的样本集合、通过双样本t检验分析(双独立样本t检验)来判断倾向性评分匹配后样本中的所有协变量的平衡情况
[JS] - [string - application] - learning notes
7-7 求解众数问题
Yyds dry goods inventory tells us 16 common usage scenarios of redis at one go
华为机器学习服务语音识别功能,让应用绘“声”绘色
还在用 SimpleDateFormat 做时间格式化?小心项目崩掉
文件包含漏洞问题
Idea creation module prompt already exists
golang convert map to json string
376. 机器任务
Selective sort method
[basic knowledge] ~ half adder & full adder
Mousse shares listed on Shenzhen Stock Exchange: becoming popular by mattress and "foreign old man", with a market value of 22.4 billion yuan
Still using simpledateformat for time formatting? Be careful of project collapse
7-8 梯云纵
[JS] - [tree] - learning notes
InnoDB, the storage engine of MySQL Architecture Principle_ Redo log and binlog
【js】-【字符串-应用】- 学习笔记