题目如下:

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.

(Figure 1)
7
3 : 8
8 : 1 : 0
2 : 7 : 4 : 4
4 : 5 : 2 : 6 : 5

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:

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

Sample Output: 30

解题思路:
这题目是需要每一层选择一点组成线路而达到最大数值,用动态规划最大限度利用已有数据情报来计算是不错的选择。在这里每一层都是一个状态,逐步递增状态,分解问题成0-2层,0-3层。。。。0-(n-1)层的最大路线价值。通过n-2层的数据转移形成n-1层,一直下分n-3层->n-2层,n-4层->n-3层。。。主体来看还是比较简单的题目。

思路代码如下:

int Method(int **n,int len)
{int res=0;for(int i=1;i<len;++i){for(int p=0;p<=i;++p){if(p==0) *((int*)n+len*i+p)+= //n[i][p]*((int*)n+len*(i-1)+p); //n[i-1][p]else if(p==i) *((int*)n+len*i+p)+=*((int*)n+len*(i-1)+(p-1)); //n[i-1][p-1]else *((int*)n+len*i+p)+=max(*((int*)n+len*(i-1)+(p-1)),*((int*)n+len*(i-1)+p));}}for(int i=0;i<len;++i)res=max(res,*((int*)n+len*(len-1)+i));//n[len-1][i]return res;
}

Arithmetic problem | The Triangle相关推荐

  1. SPOJ Problem 22:Triangle From Centroid

    已知三角形重心到三边的距离和其中一边,求面积和重心到垂心的距离. 计算几何..纯数学题 #include<cstdio> #include<cmath> int t; doub ...

  2. Arithmetic problem | Target Sum

    题目如下: You are given a list of non-negative integers, a1, a2, -, an, and a target, S. Now you have 2 ...

  3. UVA 11401 - Triangle Counting

    Problem G Triangle Counting Input: Standard Input Output: Standard Output You are given n rods of le ...

  4. HDOJ 4466 Triangle 递推

    1.当b=c时,a至少为1,所以c<=(n-1)/2 而a<=b 所以n-2*c<=c =>c>=n/3; 故共有(n-1)/2-(n/3)+(n/3?0:1)种. 2. ...

  5. 2017 ACM ICPC Asia Shenyang Regional Contest 题解(10 / 13)【每日亿题2 / 16】

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A.(2017 ICPC shenyang I)Little Boxes B.(2017 ICP ...

  6. 并行博弈树搜索算法-第6篇 百花齐放:各种并行Alpha-Beta算法

    下面开始介绍一些在Alpha-Beta算法中引入并行化的方法和算法. 6.1     并行求值(Parallel Evaluation) 游戏的博弈程序经常要在搜索深度和叶结点的求值复杂度之间进行平衡 ...

  7. Paper:GPT-3《 Language Models are Few-Shot Learners》的翻译与解读

    Paper:GPT-3< Language Models are Few-Shot Learners>的翻译与解读 目录 <GPT-3: Language Models are Fe ...

  8. 2019中山大学程序设计竞赛

    Problem A 题意:有一个长度为n的随机排列以及m个min.max操作.问最后一个操作的结果的期望 * n! 的结果. 题解: 枚举k,考虑计算结果 >= k 的排列有几个. 此时数字本质 ...

  9. 隐私保护和数据安全:区块链的隐私问题、零钞:基于zkSNARK的完美混币池、Hawk:保护合约数据私密性、Coco框架、Baby Zoe

    第十章 文章目录 第十章 一.区块链的隐私问题 1.化名和匿名 2.去匿名攻击:交易表分析 二.零钞:基于zkSNARK的完美混币池 1.零知识证明 2.零钞的运行原理 三.Hawk:保护合约数据私密 ...

最新文章

  1. opencv openpose
  2. Struts2+Hibernate分页显示实例
  3. 快速开发一个自定义 Spring Boot Starter ,希望你也会
  4. C++ Primer 5th笔记(chap 15 OOP)继承的构造函数容器
  5. UNITY IMGUI
  6. 10 分钟快速入门海量数据搜索分析引擎 Elasticearch
  7. OPENCV回调函数
  8. 4.3)深度卷积网络:目标检测
  9. 【入门4】数组 (今天刷洛谷了嘛)
  10. 美丽人生论坛看贴工具delphi版
  11. 8.9. 最大连续子段和,以及循环最大连续子段和。
  12. 收集bug开源框架_百度开源又一力作发布!炸了。。。
  13. 计算机专业西交大和哈工大,本科毕业打算深造,西交、北邮、哈工大学计算机选哪所?北邮更好...
  14. 【系统分析师之路】第五章 复盘软件工程(软件过程改进)
  15. 群晖3617可以有几个网卡_【群晖系统】黑群晖洗白13问~经典QA
  16. vc植物大战僵尸修改器简单源代码
  17. 单片机:红外遥控实验(内含红外遥控介绍+硬件原理+软件编程+配置环境)
  18. 途牛VS去哪儿VS去啊旅游产品竞品分析报告
  19. Excel查找一列中的相同值,删除该行或替换为空值
  20. CDC Schemes

热门文章

  1. 内存照片删除能恢复吗?赶紧看怎么恢复
  2. 模仿QQ左滑删除当前会话列表
  3. 苹果表主题图片爬取!
  4. javascript中的Data()对象
  5. Observability:Elastic 可观测性是什么?
  6. 小型机与pc服务器区别
  7. 双目九视清哺光仪_儿童近视眼300度怎么恢复视力,近视哺光仪对眼睛的影响
  8. matlab写泰勒中值定理,基于Matlab环境优化Taylor中值定理教学
  9. html音乐设计与安装,录音棚装修设计要求和一般方法
  10. Amaze UI框架搭建