当前位置:网站首页>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
边栏推荐
- [JS] - [array, Stack, queue, Link List basis] - Notes
- 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
- 257. 关押罪犯
- golang map clear
- 中学校园IP网络广播系统解决方案-校园数字IP广播系统方案设计指南
- 慕思股份深交所上市:靠床垫和“洋老头”走红 市值224亿
- (Smooth)ScrollToPosition doesn't work properly with RecyclerView
- Actipro WPF Controls 2022.1.2
- Installation and deployment of ganglia
- The dplyr package select function of R language moves the specified data column in the dataframe data to the first column (the first column) in the dataframe data column
猜你喜欢

Huawei machine learning service speech recognition function enables applications to paint "sound" and color

选择类排序法

Main cause of EMI - mold current
![[introduction to UVM== > episode_8] ~ sequence and sequencer, sequence hierarchy](/img/d0/7d78b00e4f6ad1e8efb73a5d472b09.png)
[introduction to UVM== > episode_8] ~ sequence and sequencer, sequence hierarchy

Dig deep into MySQL - resolve the non clustered index of MyISAM storage engine

Idea creation module prompt already exists

2021-2022中国金融数字化“新”洞察行业研究报告

Mousse shares listed on Shenzhen Stock Exchange: becoming popular by mattress and "foreign old man", with a market value of 22.4 billion yuan

基于三维GIS开发的水电工程建设方案

Volcano成Spark默认batch调度器
随机推荐
OpenSSL SSL_read: Connection was reset, errno 10054
RT thread uses RT kprintf
Laravel add helper file
Actipro WPF Controls 2022.1.2
【js】-【字符串-应用】- 学习笔记
SimpleDateFormat 格式化和解析日期的具体类
Ningde times will increase RMB 45billion: Hillhouse subscribes RMB 3billion and Zeng Yuqun still controls 23% of the equity
(Smooth)ScrollToPosition doesn't work properly with RecyclerView
Detailed explanation of online group chat and dating platform project (servlet implementation)
監聽 Markdown 文件並熱更新 Next.js 頁面
golang convert json string to map
Common regular expressions
372. 棋盘覆盖
SQL -convert function
7-7 求解众数问题
去处电脑桌面小箭头
7-5 最大子矩阵和问题
UNION ALL UNION FULL JOIN
选择类排序法
常用正则表达式