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

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 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

Source

 
 
DP
 #include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
using namespace std;
int map[][];
int main(){
int n,i,j;
cin>>n;
for(i=;i<n;i++){
for(j=;j<=i;j++){
scanf("%d",&map[i][j]);
}
}
for(i=n-;i>=;i--){
for(j=;j<=i;j++){
map[i][j]+=map[i+][j]>map[i+][j+]?map[i+][j]:map[i+][j+];
}
}
cout<<map[][]<<endl;
return ;
}

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. [LeetCode 题解]: Count and Say

    The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...

  2. [Erlang13]怎么把一个普通的进程挂入Supervisor监控树?

    简单来说:应该是在调用的start_link返回一个{ok,Pid}就可以把这个进程放入监控树Supervisor里面: -module(worker). -author("zhongwen ...

  3. Backup--BUFFERSIZE 和BUFFERCOUNT

    在备份时,可以通过设置BUFFERSIZE 和BUFFERCOUNT来控制备份的时间和CPU的消耗 使用TF 3605 和 TF 3213 来显示备份使用的 BUFFERCOUNT DBCC TRAC ...

  4. Ocelot Consul

    1首先创建一个json的配置文件,文件名随便取,我取Ocelot.json 这个配置文件有两种配置方式,第一种,手动填写 服务所在的ip和端口:第二种,用Consul进行服务发现 第一种如下: { & ...

  5. 深入了解java虚拟机(JVM) 第六章 垃圾回收算法

    一.标记清除算法 标记清除算法顾名思义,就是将需要回收的对象进行标记,然后进行清除.那么这个算法就有标记和清除两种过程.标记过程主要是通过可达性分析算法进行判断存活对象,然后遍历所有的对象来找到需要回 ...

  6. Ubuntu的中文乱码问题

    目标:使系统/服务器支持中文,能够正常显示. 1.首先,安装中文支持包language-pack-zh-hans: $ sudo apt-get install language-pack-zh-ha ...

  7. 4.iptables 网络防火墙

    [1] #如果想要iptables作为网络防火墙,iptables所在主机开启核心转发功能,以便能够转发报文. [2] #使用如下命令查看当前主机是否已经开启了核心转发,0表示为开启,1表示已开启 c ...

  8. leecode刷题(9)-- 有效的数独

    leecode刷题(9)-- 有效的数独 有效的数独 描述: 判断一个 9x9 的数独是否有效.只需要根据以下规则,验证已经填入的数字是否有效即可. 数字 1-9 在每一行只能出现一次. 数字 1-9 ...

  9. AutoCAD.Net圆弧半径标注延长线

    #region 注册RegApp public static void CheckRegApp(string regapptablename) { Database db = HostApplicat ...

  10. PHP类库生成pdf代码实例

    require_once('./tcpdf/tcpdf.php'); //引入库文件        $pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', f ...