NYOJ - The Triangle(经典dp)

The Triangle 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the left or diagonally down to the right. 输入 Your program is to read from standard input. The first line contains one integer N: the number of rows in the triangle. The following N lines describe the data of the triangle. The number of rows in the triangle is > 1 but <= 100. The numbers in the triangle, all integers, are between 0 and 99. 输出 Your program is to write to standard output. The highest sum is written as an integer. 立即下载

The Triangle

时间限制:1000 ms  |           内存限制:65535 KB
难度:4
描述

7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
(Figure 1)
Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the left or diagonally down to the right.

输入
Your program is to read from standard input. The first line contains one integer N: the number of rows in the triangle. The following N lines describe the data of the triangle. The number of rows in the triangle is > 1 but <= 100. The numbers in the triangle, all integers, are between 0 and 99.
输出
Your program is to write to standard output. The highest sum is written as an integer.
样例输入
5
7
3 8
8 1 0 
2 7 4 4
4 5 2 6 5
样例输出
30

这个是经典的dp问题,可以从后面向前递推,那么,动态转移方程为a[i][j] += max(a[i+1][j],a[i+1],[j+1]),下面是具体的代码,这里提供参考。

#include <stdio.h>

int max(int n,int m)
{
	return n > m ? n : m;
}

int main()
{
	int a[101][101];
	int n,i,j;
	while(scanf("%d",&n) != EOF)
	{
		for(i = 0; i < n; i++)
		{
			for(j = 0; j <= i; j++)
			{
				scanf("%d",&a[i][j]);
			}
		}
		for(i = n-2; i >= 0; i--)
		{
			for(j = 0; j <= i; j++)
			{
				a[i][j] += max(a[i+1][j],a[i+1][j+1]);
			}
		}
		printf("%d\n",a[0][0]);
	}
	return 0;
}
升级最新IDEA版本(2022.1.1) 阅读详情

相关推荐

Frida实战:如何用HashMap.put拦截法快速定位安卓App加密参数(附完整脚本)

本文详细介绍了如何使用Frida拦截HashMap.put方法快速定位安卓App加密参数,提供完整脚本和实战案例。通过动态分析技术,相比传统静态分析大幅提升效率,适用于电商、社交、金融等场景的加密参数定位。

jump7的博客 273

qdu 15信安 vjudge

vjudge

qq1574311549的博客 1243

达芬奇Pro开发板硬件验证全流程指南

FPGA开发板硬件验证是嵌入式系统可靠性的基石,其核心在于理解SoC启动时序、IO资源映射与高速接口物理层约束。基于Xilinx Zynq-7000异构架构的开发平台,需围绕电源完整性、时钟稳定性、信号完整性及软硬协同启动链路展开分层测试。技术价值体现在规避量产失效率、支撑高可靠工业控制与实时图像处理等场景。典型应用涵盖千兆以太网通信验证、DVP摄像头与RGB LCD显示链路调试、以及SFP+光纤接口PRBS误码率测试。本文聚焦达芬奇Pro系列开发板,深入解析JTAG下载、QSPI Flash重烧录、RGM

weixin_42453228的博客 139

码农的表白

码农的创意的数字表达爱意的方式,包括利用编程技巧生成心形和玫瑰图案,以及使用二进制和压缩算法进行信息加密。首先,通过在Sublime Text中输入特定的数字序列并搜索所有“9”,意外地生成了一种心形图案。接着,介绍了两种在HTML中使用Canvas元素绘制动态心形的方法,可通过将提供的JavaScript代码直接粘贴至Chrome浏览器的地址栏来预览效果。此外,还展示了一种用“x”和“o”代表二进制的“1”和“0”的编码方式,通过简单的C++程序实现对“I Love You”的编码与解码。进一步,文

生活在别处 9万+

kettle多表数据迁移

点击 文件——新建——作业,在左侧的 核心对象 标签下选择 通用,双击添加一个 start ,一个 转换 ,一个 作业 和一个 成功 到右侧的作业面板,这些作业项都可以改名字。点击文件—新建—转换,在左侧的 核心对象 标签下选择 输入 下的 表输入,双击添加到右侧的转换面板,再选择 作业 下的 复制记录到结果 ,双击添加到右侧的转换面板。新建转换,在左侧的 核心对象 标签下选择 作业 下的 从结果获取记录,双击添加到右侧的转换面板,再选择 作业 下的 设置变量 ,双击添加到右侧的转换面板。

u014061745的博客 1353

由于找不到mfc110u.dll,无法继续执行代码,重新安装程序可能会解决此问题的 解决方案

本文主要介绍了由于找不到mfc110.dll,无法继续执行代码的解决方案,希望能对使用Windows的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 5万+

杭电-oj Palindrome

翻译 Problem Description A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program which, given a string, determines the minimal number of characters to be inserted

JIAY_WX的博客 331

【GameFramework框架内置模块】1、全局配置(Config)

这是GameFramework框架内置模块的第一篇,全局配置Config,讲解这些模块的时候会尽量的涉及介绍、为什么使用、如何使用、代码分析这几块,让大家可以知其然,也知其所以然。全局配置表,存储了一些游戏中使用的全局的参数配置,比如玩家的初始速度、游戏初始音量等。全局配置表的结构跟DataTable结构类似,也是列行+键值对,只是没有ID这一列,因为全局配置也不需要用ID去查询, 是直接使用key值进行查询。

CSDN博客专家,Unity3D高级软件工程师,《Unity 3D从入门到实战》作者。 5909

The Triangle 经典DP

Description 正在上传… 取消 Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers passed on a route that starts at the top and ends somewhere on the base...

菲菲家的吴先森 870

【Claude Code 源码解析教程】总体大纲

本教程旨在深入解析 Anthropic Claude Code 项目的源码架构和实现细节。Claude Code 是一个基于 TypeScript + Bun 构建的 AI 编程助手 CLI 工具,代号 "Tengu",具有复杂的多模块架构和丰富的功能特性。本教程基于Claude Code 的源码分析来生成,将帮助您全面掌握 Claude Code 的源码架构和实现细节,为开发类似 AI 编程助手工具奠定坚实基础。

rengang66的博客 397

LLC 谐振变换器开发设计1

本文档详细介绍了基于DSP28335的LLC谐振变换器开发设计。系统采用频率调制(FM)控制方式,实现高效率、高功率密度的隔离型DC/DC变换。文档阐述了LLC拓扑结构和工作原理,给出了谐振频率、品质因数等关键参数的计算公式。硬件设计包括功率器件选型和采样电路实现,软件部分提供了DSP28335的核心控制算法和代码示例,涵盖频率转换、PI控制和PWM生成。系统还设计了启动策略和保护机制,确保可靠运行。该设计实现了主开关零电压开通和低纹波输出特性。

352

hdu3868 The Triangle ransmitter

The Triangle ransmitterTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 219    Accept

喵呜的Blog 1594

基于传统算法的半导体晶圆缺陷检测原理及代码(二)

了解基于传统算法的半导体晶圆缺陷检测原理和方法,对于深入理解半导体制造工艺和质量控制具有重要意义。在半导体制造技术持续创新的浪潮中,基于传统算法的缺陷检测技术也将不断演进,为半导体产业的高质量发展提供坚实可靠的技术支撑,确保在芯片制造的每一个环节都能精准识别和管控缺陷,推动半导体产业迈向更高的发展水平。基于传统算法的半导体晶圆缺陷检测技术在半导体制造的长期发展历程中扮演了重要角色,凭借其成熟的技术体系、较快的检测速度和相对较低的成本,在各个工艺阶段为保障晶圆质量发挥了关键作用。

m0_44975814的博客 2230

nyoj 18 The Triangle 【经典dp】

The Triangle 时间限制:1000 ms  |           内存限制:65535 KB 难度:4 描述 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure 1 shows a number triangle. Write a program that calculates the highest sum o

世界很大 545

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

nyoj18 The Triangle

题目来源:http://acm.nyist.net/JudgeOnline/problem.php?pid=18 The Triangle 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure 1 shows a numb

PandaLHC 493

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

nyoj18 The Triangle(dp)

The Triangle 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 73 88 1 02 7 4 44 5 2 6 5(Figure 1)Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers p...

angtongyou1893的博客 141

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

nyoj18 The Triangle dp

很基础的动态规划问题。 用dp[i][j]二维数组表示达到该位置的最大和。 按从下到上的顺序遍历。 #include &lt;iostream&gt; #include &lt;algorithm&gt; #include &lt;cstring&gt; using namespace std; int a[101][101]; int dp[101][101]; int main()...

skykone1的博客 150

NYOJ 题目18 The Triangle

描述 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers passed on a route that starts at the top and ends some

光明~~~ 2万+

nyoj_18 The Triangle

The Triangle 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure 1 shows a number triangle. Write a program that calculates the highest sum of

风雨程序路 483

NYOJ 18 The Triangle(dp + 记忆化)

The Triangle 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers

x_y_q_的博客 663

nyoj18The Triangle数塔

The Triangle时间限制:1000 ms  |  内存限制:65535 KB难度:4描述73 88 1 02 7 4 44 5 2 6 5(Figure 1)Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers passed on a route that s...

popcjz的博客 1506

NYOJ 18. The triangle(基础DP)

The Triangle 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure 1 shows a number triangle. Write a program that calculates the highest sum of

cr496352127的博客 357

NYOJ 18 The Triangle(基础dp)

 The Triangle时间限制:1000 ms  |  内存限制:65535 KB    难度:4描述 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers pa...

Jackie035 252

NYOJ 18 The Triangle 填表法,普通dp

题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=18 The Triangle 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure 1 shows a number tr...

weixin_30599769的博客 143

NYOJ 18 The Triangle(简单dp)

The Triangle 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers p

滴水穿石,慢慢积累,总会有成果 596

NYOJ 18-The Triangle(典型DP)

//典型数塔问题 //可以自顶向下,也可以自底向上 //转移方程dp[i][j] = max(dp[i+1][j], dp[i+1][j+1]) + dp[i][j]; //结果输出dp[0][0] #include #include #define maxn 105 using namespace std; int dp[maxn][maxn]; int main() { int

尘封丶的博客 321
上一篇: NYOJ - 最大和(DP)
下一篇: NYOJ - 找球号(一)(二分)
SevenMIT
博客等级 码龄15年 60粉丝 162原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址