当前位置:网站首页>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
边栏推荐
- The R language uses the matchit package for propensity matching analysis and match The data function constructs the matched sample set, and judges the balance of all covariates in the sample after the
- 【UVM入门 ===> Episode_8 】~ Sequence 和 Sequencer、Sequence 层次化
- Jetpack Compose 最新进展
- Installation and deployment of ganglia
- Helix distance of point
- 明天就是PMP考试了(6月25日),这些大家都了解了吗?
- 7-7 求解众数问题
- Super detailed cookie addition, deletion, modification and query
- Quickly build KVM virtual machine on # yyds dry goods inventory # physical machine
- 国内有哪些好的智能家居品牌支持homekit?
猜你喜欢
随机推荐
[JS] - [array, Stack, queue, Link List basis] - Notes
基本数据类型
Detailed explanation of online group chat and dating platform project (servlet implementation)
Installing IBM CPLEX academic edition | CONDA installing CPLEX
SQL -convert function
[JS] - [tree] - learning notes
Volcano成Spark默认batch调度器
js监听页面或元素scroll事件,滚动到底部或顶部
选择类排序法
OpenSSL SSL_ read: Connection was reset, errno 10054
Actipro WPF Controls 2022.1.2
376. Tâches mécaniques
InnoDB, the storage engine of MySQL Architecture Principle_ Redo log and binlog
一文理解OpenStack网络
379. 捉迷藏
UNION ALL UNION FULL JOIN
从客户端到服务器
Docker-mysql8-master-slave
Laravel scheduled task
Main cause of EMI - mold current









