当前位置:网站首页>7-7 digital triangle
7-7 digital triangle
2022-06-24 23:31:00 【White -】
7-7 Digital triangle
Look at the digital pyramid below . Write a program to find the path from the top to the bottom , Make the path go through the number and maximum . Each step can go from the current point to the lower left point or to the lower right point .
In the example above , from 13 To 8 To 26 To 15 To 24 The path of produces the largest sum 86.
Input format :
The first line contains R(1≤ R≤1000), Represents the number of rows .
The number of integers contained in a specific line of the pyramid of numbers in each subsequent line .
All supplied integers are nonnegative and not greater than 100.
Output format :
A single line , Include the largest sum that can be obtained .
sample input :
5
13
11 8
12 7 26
6 14 15 8
12 7 13 24 11
sample output :
86
Code :
#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 3、 ... and
边栏推荐
- 中学校园IP网络广播系统解决方案-校园数字IP广播系统方案设计指南
- 7-2 求解买股票问题
- 378. 骑士放置
- sql -CONVERT函数
- [JS] - [stack, team - application] - learning notes
- 376. machine tasks
- Laravel message queue
- QT to place the form in the lower right corner of the desktop
- Simple use of libnum Library (hexadecimal string conversion)
- Notes for laravel model
猜你喜欢
随机推荐
R语言使用MatchIt包进行倾向性匹配分析、使用match.data函数构建匹配后的样本集合、通过双样本t检验分析(双独立样本t检验)来判断倾向性评分匹配后样本中的所有协变量的平衡情况
監聽 Markdown 文件並熱更新 Next.js 頁面
宁德时代定增450亿:高瓴认购30亿 曾毓群仍控制23%股权
Design and practice of vivo server monitoring architecture
379. 捉迷藏
Gocolly manual
Laravel user authorization
#22Map介绍与API
sql -CONVERT函数
OpenSSL SSL_read: Connection was reset, errno 10054
[JS] - [array, Stack, queue, Link List basis] - Notes
throttle-debounce.js:一个小型的防抖节流函数库
R语言dplyr包group_by函数和summarise_at函数计算dataframe计算不同分组的计数个数和均值(Summarise Data by Categorical Variable)
[JS] - [string - application] - learning notes
Chapter VI skills related to e-learning 5 (super parameter verification)
Laravel study notes
Mousse shares listed on Shenzhen Stock Exchange: becoming popular by mattress and "foreign old man", with a market value of 22.4 billion yuan
明天就是PMP考试了(6月25日),这些大家都了解了吗?
2021-2022中国金融数字化“新”洞察行业研究报告
RT-thread使用rt-kprintf