当前位置:网站首页>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
边栏推荐
猜你喜欢

(Smooth)ScrollToPosition doesn't work properly with RecyclerView

Ningde times will increase RMB 45billion: Hillhouse subscribes RMB 3billion and Zeng Yuqun still controls 23% of the equity

选择类排序法

Hydropower project construction scheme based on 3D GIS Development

HarmonyOS访问数据库实例(3)--用ORM Bee测下HarmonyOS到底有多牛

宁德时代定增450亿:高瓴认购30亿 曾毓群仍控制23%股权

Installation and deployment of ganglia

基于三维GIS开发的水电工程建设方案

Laravel pagoda security configuration

Simpledateformat concrete classes for formatting and parsing dates
随机推荐
Docker-mysql8-master-slave
#22Map介绍与API
R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用AIC函数比较两个模型的AIC值的差异(简单模型和复杂模型)
R语言使用MatchIt包进行倾向性匹配分析、使用match.data函数构建匹配后的样本集合、通过双样本t检验分析(双独立样本t检验)来判断倾向性评分匹配后样本中的所有协变量的平衡情况
golang convert json string to map
Laravel study notes
Detailed explanation of online group chat and dating platform project (servlet implementation)
RT thread uses RT kprintf
[JS] - [array application] - learning notes
HarmonyOS访问数据库实例(3)--用ORM Bee测下HarmonyOS到底有多牛
QT to place the form in the lower right corner of the desktop
golang map clear
[JS] - [tree] - learning notes
还在用 SimpleDateFormat 做时间格式化?小心项目崩掉
go 语言指针,值引用和指针引用
2021-2022中国金融数字化“新”洞察行业研究报告
国内有哪些好的智能家居品牌支持homekit?
点的螺旋距离
libnum库简单使用(进制字符串转换)
[basic knowledge] ~ half adder & full adder