The Triangle
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 39169   Accepted: 23518

Description

  1. 7
    3 8
    8 1 0
    2 7 4 4
    4 5 2 6 5
  2.  
  3. (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

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

Sample Output

  1. 30

Source

 
 
DP
  1. #include<cstdio>
  2. #include<cmath>
  3. #include<cstring>
  4. #include<iostream>
  5. using namespace std;
  6. int map[][];
  7. int main(){
  8. int n,i,j;
  9. cin>>n;
  10. for(i=;i<n;i++){
  11. for(j=;j<=i;j++){
  12. scanf("%d",&map[i][j]);
  13. }
  14. }
  15. for(i=n-;i>=;i--){
  16. for(j=;j<=i;j++){
  17. map[i][j]+=map[i+][j]>map[i+][j+]?map[i+][j]:map[i+][j+];
  18. }
  19. }
  20. cout<<map[][]<<endl;
  21. return ;
  22. }

poj 1168 The Triangle的更多相关文章

  1. POJ 1163 The Triangle(简单动态规划)

    http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  2. 【POJ】2954 Triangle(pick定理)

    http://poj.org/problem?id=2954 表示我交了20+次... 为什么呢?因为多组数据我是这样判断的:da=sum{a[i].x+a[i].y},然后!da就表示没有数据了QA ...

  3. OpenJudge/Poj 1163 The Triangle

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

  4. POJ 1163 The Triangle【dp+杨辉三角加强版(递归)】

    The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 49955   Accepted: 30177 De ...

  5. poj 1163 The Triangle

    The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43809   Accepted: 26430 De ...

  6. Poj 1163 The Triangle 之解题报告

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42232   Accepted: 25527 Description 7 3 ...

  7. poj 1163 The Triangle 搜索 难度:0

    The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37931   Accepted: 22779 De ...

  8. POJ 1163 The Triangle DP题解

    寻找路径,动态规划法题解. 本题和Leetcode的triangle题目几乎相同一样的,本题要求的是找到最大路径和. 逆向思维.从底往上查找起就能够了. 由于从上往下能够扩展到非常多路径.而从下往上个 ...

  9. POJ 2986 A Triangle and a Circle(三角形和圆形求交)

    Description Given one triangle and one circle in the plane. Your task is to calculate the common are ...

随机推荐

  1. 无线显示技术:WiDi,WLAN Display,Air Play,Miracast的摘抄

    除了标题提到的WIDI,WLAN Display,Air Play之外,还有Miracast与DLNA的概念,他们之间的区别和联系是什么呢? WIDI: WiDi是英特尔主导的无线音视频传输技术,这也 ...

  2. WinAPI 字符及字符串函数(10): lstrcpy - 复制字符串

    unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, For ...

  3. Android-ListView-ArrayAdapter

    我在上一篇博客中Android-动态添加控件到ScrollView,写到可以用Java动态添加控件到Scrollview的孩子LinearLayout里面去,这种方式是不合理的,因为这种方式是一次性把 ...

  4. [LeetCode 题解]: ZigZag Conversion

    前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 The string ...

  5. pageadmin网站制作 如何修改和管理网站模板

    在使用pageadmin CMS 的同时,遇到问题可以参考官网帮助中心.1.网站模板目录地址/templates目录, 2.点击展开后,每个目录就是一个网站模板, 前端设计师制作的新版本都可以放到这个 ...

  6. Thinkpad R400无线网络一个都不见了!

    今天,我的Thinkpad R400无线网络一个都不见了,用手机测试,家里的无线网络正常.反复开关无线网络控制硬件开关,还是不好使,无线网络那个图标里面,并没有无线网络.上网搜索一下,发现小黑居然还有 ...

  7. 2018版OCP考试052最新题库及答案-35题

    35.Your database is using Automatic Memory Management. Which two SGA components must be managed manu ...

  8. SFML从入门到放弃(0) 配置环境

    SFML从入门到放弃(0) 配置环境 恩..开始划水..学sfml的时候顺便做点笔记什么的.. 安装 在linux里面打开终端 然后输入 sudo apt-get install libsfml-de ...

  9. Ionic2文档整理

    来自:Rainey's Blog 原文地址:http://rainey.space/2016/04/06/Ionic2_Chinese_Document/ Github:https://github. ...

  10. 牛客网NOIP赛前集训营-提高组(第四场)B区间

    牛客网NOIP赛前集训营-提高组(第四场)B区间 题目描述 给出一个序列$ a_1  \dots   a_n$. 定义一个区间 \([l,r]\) 是好的,当且仅当这个区间中存在一个 \(i\),使得 ...