当前位置:网站首页>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 pagoda security configuration
- docker-mysql8-主从
- Construction equipment [6]
- Financial management [3]
- laravel 添加helper文件
- Building Survey [1]
- Mycms we media CMS V3.0, resource push optimization, new free template
- Uncover the secrets of Huawei cloud enterprise redis issue 16: acid'true' transactions beyond open source redis
- Paddledtx v1.0 has been released, and its security and flexibility have been comprehensively improved!
- 02_ Springboot starter case
猜你喜欢

EMI的主要原因-工模电流

Concurrent shared model management

安装IBM CPLEX学术版 academic edition | conda 安装 CPLEX

Record the range of data that MySQL update will lock
Mycms we media CMS V3.0, resource push optimization, new free template

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

Online group chat and dating platform test point

#22Map介绍与API

Installation and deployment of ganglia

斐波那契
随机推荐
Financial management [4]
Force deduction solution summary 515- find the maximum value in each tree row
laravel 创建 service层
【js】-【数组应用】-学习笔记
案例解析:用「度量」提升企业研发效能|ONES Talk
Laravel authentication module auth
去处电脑桌面小箭头
【js】-【链表-应用】-学习笔记
Tech talk activity review kubernetes skills of cloud native Devops
372. 棋盘覆盖
记录一下MySql update会锁定哪些范围的数据
Uncover the secrets of Huawei cloud enterprise redis issue 16: acid'true' transactions beyond open source redis
R语言dplyr包select函数将dataframe数据中的指定数据列移动到dataframe数据列中的第一列(首列)
Basic data type
文件包含漏洞问题
Still using simpledateformat for time formatting? Be careful of project collapse
[JS] - [array application] - learning notes
Laravel 认证模块 auth
【js】-【数组、栈、队列、链表基础】-笔记
伪原创智能改写api百度-收录良好