当前位置:网站首页>7-7 数字三角形
7-7 数字三角形
2022-06-24 19:43:00 【白—】
7-7 数字三角形
观察下面的数字金字塔。写一个程序查找从最高点到底部任意处结束的路径,使路径经过数字的和最大。每一步可以从当前点走到左下方的点也可以到达右下方的点。
在上面的样例中,从13到8到26到15到24的路径产生了最大的和86。
输入格式:
第一个行包含R(1≤ R≤1000),表示行的数目。
后面每行为这个数字金字塔特定行包含的整数。
所有的被供应的整数是非负的且不大于100。
输出格式:
单独的一行,包含那个可能得到的最大的和。
输入样例:
5
13
11 8
12 7 26
6 14 15 8
12 7 13 24 11
输出样例:
86
代码:
#include <stdio.h>
#include <stdlib.h>
int n;
int a[1010][1010];
int vis[1010][1010];
int findmax(int a,int b)
{
return a>=b?a:b;
}
int fid(int x,int y)
{
if(x>n||y>n)
return 0;
if(vis[x][y]!=0)
return vis[x][y];
int l=fid(x+1,y)+a[x][y];
int r=fid(x+1,y+1)+a[x][y];
return vis[x][y]=findmax(l,r);
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
for(int j=1;j<=i;j++)
scanf("%d",&a[i][j]);
printf("%d",fid(1,1));
return 0;
}
202206222103三
边栏推荐
- [introduction to UVM== > episode_8] ~ sequence and sequencer, sequence hierarchy
- F29oc analysis
- Selection (029) - what is the output of the following code?
- 376. machine tasks
- 376. Tâches mécaniques
- Ningde times will increase RMB 45billion: Hillhouse subscribes RMB 3billion and Zeng Yuqun still controls 23% of the equity
- Laravel scheduled task
- 376. 機器任務
- idea创建模块提示已存在
- [JS] - [linked list - application] - learning notes
猜你喜欢

Simpledateformat concrete classes for formatting and parsing dates
![[introduction to UVM== > episode_8] ~ sequence and sequencer, sequence hierarchy](/img/d0/7d78b00e4f6ad1e8efb73a5d472b09.png)
[introduction to UVM== > episode_8] ~ sequence and sequencer, sequence hierarchy

File contains vulnerability issues

Installation and deployment of ganglia
![[JS] - [string - application] - learning notes](/img/dc/f35979b094f04c0ee13b3354c7741d.png)
[JS] - [string - application] - learning notes

Main cause of EMI - mold current

【基础知识】~ 半加器 & 全加器

03_ Spingboot core profile

还在用 SimpleDateFormat 做时间格式化?小心项目崩掉

【js】-【數組、棧、隊列、鏈錶基礎】-筆記
随机推荐
laravel 创建 service层
Construction equipment [5]
安装IBM CPLEX学术版 academic edition | conda 安装 CPLEX
华为机器学习服务语音识别功能,让应用绘“声”绘色
Record the range of data that MySQL update will lock
#22Map介绍与API
golang convert json string to map
Common regular expressions
Actipro WPF Controls 2022.1.2
Building Survey [3]
数字IC设计经验整理(二)
Selection (028) - what is the output of the following code?
File contains vulnerability issues
【js】-【链表-应用】-学习笔记
Accounting standards for business enterprises application [5]
Dig deep into MySQL - resolve the non clustered index of MyISAM storage engine
R语言使用epiDisplay包的aggregate函数将数值变量基于因子变量拆分为不同的子集,计算每个子集的汇总统计信息、自定义FUN参数为多个统计量函数名称的列表计算多个统计量
UNION ALL UNION FULL JOIN
laravel 添加helper文件
376. 机器任务