当前位置:网站首页>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三
边栏推荐
- Laravel 认证模块 auth
- R语言dplyr包select函数将dataframe数据中的指定数据列移动到dataframe数据列中的第一列(首列)
- Paddledtx v1.0 has been released, and its security and flexibility have been comprehensively improved!
- What good smart home brands in China support homekit?
- Building Survey [2]
- golang convert map to json string
- [JS] - [tree] - learning notes
- Main cause of EMI - mold current
- Listen to the markdown file and hot update next JS page
- R language uses the polR function of mass package to build an ordered multi classification logistic regression model, and uses exp function, confint function and coef function to obtain the confidence
猜你喜欢

Dig deep into MySQL - resolve the non clustered index of MyISAM storage engine
![[JS] - [array, Stack, queue, Link List basis] - Notes](/img/c6/a1bd3b8ef6476d7d549abcb442949a.png)
[JS] - [array, Stack, queue, Link List basis] - Notes
![[JS] - [tree] - learning notes](/img/62/de4fa2a7c5e52c461b8be4a884a395.png)
[JS] - [tree] - learning notes

Tech talk activity review kubernetes skills of cloud native Devops

第六章 网络学习相关技巧5(超参数验证)

03_ Spingboot core profile

RT-thread使用rt-kprintf

【js】-【栈、队-应用】-学习笔记

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

Epics record reference 2 -- epics process database concept
随机推荐
Blogs personal blog test point (manual test)
QT to place the form in the lower right corner of the desktop
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
Gocolly manual
Fibonacci
【UVM入门 ===> Episode_8 】~ Sequence 和 Sequencer、Sequence 层次化
【js】-【链表-应用】-学习笔记
372. 棋盘覆盖
Dig deep into MySQL - resolve the clustered index / secondary index / federated index of InnoDB storage engine
Laravel creates a service layer
Uncover the secrets of Huawei cloud enterprise redis issue 16: acid'true' transactions beyond open source redis
File contains vulnerability issues
SQL -convert function
[JS] - [string - application] - learning notes
監聽 Markdown 文件並熱更新 Next.js 頁面
laravel 消息队列
Building Survey [3]
常用正则表达式
斐波那契
【js】-【数组应用】-学习笔记