当前位置:网站首页>7-9 寻宝路线
7-9 寻宝路线
2022-06-24 19:43:00 【白—】
7-9 寻宝路线
在一个m行n列方格矩阵中,每一个方格内摆放着价值不等的宝贝(价值可正可负),让小明感到好奇的是,从左上角到达右下角的所有可能路线中,能捡到宝贝的价值总和最大是多少?而且这种达到最大值的路线
又有多少条?【注意:只能从一个格子向下或向右走到相邻格子,并且走到的格子宝贝一定会被捡起。】
输入格式:
第一行为整数m,n(均不大于100),下一行开始会有一个m行n列的整数方阵,对应方格矩阵中的宝贝价值(这些值的绝对值都不超过500)。
输出格式:
单独一行输出2个整数,分别为能捡到宝贝价值总和的最大值和达到最大值的路线数量,2个整数间隔一个空格。
输入样例:
在这里给出一组输入。例如:
4 5
2 -1 6 -2 9
-3 2 5 -5 1
5 8 3 -2 4
5 2 8 -4 7
输出样例:
对应的输出为:
26 3
代码:
#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三
边栏推荐
- laravel 宝塔安全配置
- File contains vulnerability issues
- [JS] - [stack, team - application] - learning notes
- R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用AIC函数比较两个模型的AIC值的差异(简单模型和复杂模型)
- Financial management [4]
- [JS] - [array, stack, queue, linked list basics] - Notes
- Idea creation module prompt already exists
- golang convert map to json string
- Blogs personal blog test point (manual test)
- F29oc analysis
猜你喜欢

Pseudo original intelligent rewriting API Baidu - good collection

File contains vulnerability issues

Online group chat and dating platform test point
![[JS] - [string - application] - learning notes](/img/dc/f35979b094f04c0ee13b3354c7741d.png)
[JS] - [string - application] - learning notes

【js】-【树】-学习笔记

Still using simpledateformat for time formatting? Be careful of project collapse

Detailed explanation of online group chat and dating platform project (servlet implementation)
![[JS] - [tree] - learning notes](/img/62/de4fa2a7c5e52c461b8be4a884a395.png)
[JS] - [tree] - learning notes

Tech talk activity review kubernetes skills of cloud native Devops

【js】-【栈、队-应用】-学习笔记
随机推荐
Latest development of jetpack compose
[basic knowledge] ~ half adder & full adder
斐波那契
基本数据类型
372. 棋盘覆盖
宁德时代定增450亿:高瓴认购30亿 曾毓群仍控制23%股权
OpenSSL SSL_read: Connection was reset, errno 10054
Laravel creates a service layer
InnoDB, the storage engine of MySQL Architecture Principle_ Redo log and binlog
【基础知识】~ 半加器 & 全加器
Whereabouts computer desktop small arrow
力扣解法汇总515-在每个树行中找最大值
laravel 宝塔安全配置
EMI的主要原因-工模电流
Idea creation module prompt already exists
Selection (027) - what is the output of the following code?
Common regular expressions
Concurrent shared model management
Daily practice (22): maximum sum of continuous subarrays
[introduction to UVM== > episode_8] ~ sequence and sequencer, sequence hierarchy