蒟蒻的第一篇题解吧,,,也是蒟蒻的第一个AC的DP题。

感觉这个应该是当年的一道签到题了。。。

题目是这样的。。。(蒟蒻从自家学校OJ上扒的,不知道是不是,不是也凑合着当是看吧23333)

Description

        73   88   1   02   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.

Input

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.

Output

Your program is to write to standard output. The highest sum is written as an integer.

Sample Input

5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5

Sample Output

30

读完题就会发现这是一道标准的不能再标准的DP题了,状态转移方程是f[i][j] = max(f[i - 1][j], f[i - 1][ j - 1]) (蒟蒻不会写这东西,要是写错了dalao不要喷qwq)

然后就是套循环实现了。。。在不要求原数据的情况下可以直接用一个数组来实现,应该早就有dalao想到这个方法了。。。

不多说了,直接贴代码啦。(蒟蒻的代码还是太繁琐了)

#include <iostream>
#include <cstring>
#define max(a,b) ((a)>(b)?(a):(b))typedef long long ll;int main()
{using namespace std;long long n;cin >> n;int* ans = new int[n];int now = 0;ll index = 0;memset(ans, 0, sizeof(int) * n);for (ll i = 0; i < n; i++){for (ll l = 0; l <= i; l++){cin >> now;ans[i - l] = now + max(ans[i -l], ans[i - l - 1]);}}int max = 0;for (int i = 1; i < n; i++){if (ans[i] > ans[max])max = i;}max = ans[max];cout << max;return 0;
}

IOI 1994 The_Triangle 题解相关推荐

  1. 【第二届】无锡太湖学院ICPC校队对抗赛原创 IOI D题题解

    题目描述 圣诞节快到了,哈尔维亚的一群强盗(数量为m)正在策划着抢劫圣诞老人的礼物,由于圣诞老人会操纵魔法来抵御,强盗们在抢劫的过程中会耗费生命力,第 i 个强盗有 ai 点生命力,圣诞老人一共带着 ...

  2. 【动态规划】Part1

    1. 硬币找零 题目描述:假设有几种硬币,如1.3.5,并且数量无限.请找出能够组成某个数目的找零所使用最少的硬币数. 分析:   dp [0] = 0            dp [1] = 1 + ...

  3. OpenJudge/Poj 1163 The Triangle

    1.链接地址: http://bailian.openjudge.cn/practice/1163 http://poj.org/problem?id=1163 2.题目: 总时间限制: 1000ms ...

  4. The Triangle

    题目限制 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 59262 Accepted: 35557 时间限制: 1000ms 内 ...

  5. POJ1164 The Castle【DFS】

    The Castle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8317 Accepted: 4693 Descriptio ...

  6. Bailian2760 数字三角形【DP】

    2760:数字三角形 描述 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (图1) 图1给出了一个数字三角形.从三角形的顶部到底部有很多条不同的路径.对于每条路径,把路径上面的数加起来可 ...

  7. NOI WC 2019 小结

    Day 1 评测系统与参赛策略 王逸松 松松松手把手教你如何搭建评测系统(掉线-) 不过有一点实用的 linux 下 time ./a 可以看a的运行时间 顺便以赠送小黄鸭为评测鸭打了一波广告 既然拿 ...

  8. The Triangle(数字三角形)

    题目叙述 Description 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 p ...

  9. 牛客IOI周赛26-提高组(逆序对,对序列,未曾设想的道路) 题解

    文章目录 逆序对 对序列 未曾设想的道路 牛客IOI周赛26-提高组 逆序对 这种套路之前已经见过几次了,肯定不是模拟操作数列 opt 1 对于i∈[1,l)⋃(r,n]i∈[1,l)\bigcup( ...

最新文章

  1. 大学基础课程之重要性
  2. 使用admodify工具修改用户主目录时的注意事项
  3. Win11系统下Excel怎么把0变成空白
  4. 如何使用Native Messaging API 打开window程序
  5. SqlServer 对 数据类型 text 的操作
  6. 基于android的团购app设计与实现,基于Android的掌上团购App设计与实现
  7. tensorflow如何微调时如何只训练后两层_XLNet只存在于论文?都替你封装好了还不来用!...
  8. 本以为用的MyBatis框架就万无一失了,没想到还是被黑客注入了,我真的无语了!...
  9. 多年收集的一些稀有软件4
  10. 计算机无法安装蓝牙驱动,win10蓝牙驱动装不了怎么办_win10电脑蓝牙驱动无法安装处理方法-win7之家...
  11. 【QT】QT事件处理
  12. ZInt支持中文例子
  13. php 豆瓣api_豆瓣申请API Key教程
  14. 雷电三接口有什么用_三坐标为什么用汽浮轴承?
  15. IDEA+Java控制台实现医院管理系统
  16. c++实验3—定期存款利息计算器
  17. 出错记录:Error: package or namespace load failed for ‘DESeq2’:没有这个DLL ‘BiocParallel’:是不是没有为此架构安装?
  18. 阅读文献“Language Models are Unsupervised Multitask Learner”(GPT-2)
  19. 电脑psp模拟器(ppsspp) v1.0.0 中文版​
  20. 倾角传感器的性能精度理解文章

热门文章

  1. 用一年的数据预测下一年数据_一年的招聘数据中的经验教训
  2. PHP修改图片像素大小
  3. Pixelmator Pro为您抓住照片的质感,适合每个人的专业编辑图像工具
  4. web手机端真机测试
  5. 基于51单片机和物联网的智能家居系统(ESP8266物联网模块)
  6. 5-2 基于判定的测试
  7. MAC电脑DNS劫持解决方法
  8. 失传千年AE特效真经(三)
  9. win10强制关闭飞行模式_win10笔记本突然连不上wifi怎么办?
  10. 近期尝试UR5和PhantomOmni的联动仿真出现的问题