Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 44997   Accepted: 27174

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

入门水题233

 /**/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int a[][];
int n;
int main(){
scanf("%d",&n);
int i,j;
for(i=;i<=n;i++)
for(j=;j<=i;j++)
scanf("%d",&a[i][j]);
for(i=n-;i;i--)
for(j=;j<=i;j++){
a[i][j]+=max(a[i+][j],a[i+][j+]);
}
printf("%d\n",a[][]);
return ;
}

POJ1163 The Triangle的更多相关文章

  1. POJ1163——The Triangle

    Description 73 88 1 02 7 4 44 5 2 6 5 (Figure 1) Figure 1 shows a number triangle. Write a program t ...

  2. POJ1163 The Triangle 【DP】

    The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 36918   Accepted: 22117 De ...

  3. (数字三角形)POJ1163 The Triangle

    The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 59698   Accepted: 35792 De ...

  4. Poj1163 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 pro ...

  5. poj-3176 Cow Bowling &&poj-1163 The Triangle && hihocoder #1037 : 数字三角形 (基础dp)

    经典的数塔模型. 动态转移方程:  dp[i][j]=max(dp[i+1][j],dp[i+1][j+1])+p[i][j]; #include <iostream> #include ...

  6. POJ1163 The Triangle: 倒三角形问题

    经典的DP问题,DP思想也很直接: 直接贴代码: #include<iostream> #include<cstdio> #include<algorithm> # ...

  7. [LeetCode] Triangle 三角形

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  8. [LeetCode] Pascal's Triangle II 杨辉三角之二

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  9. [LeetCode] Pascal's Triangle 杨辉三角

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

随机推荐

  1. python__高级 : 动态添加 对象属性, 类属性, 对象实例方法, 类静态方法, 类方法

    给对象添加实例属性,可以直接这样  t.age = 18   ( 假设 t = Test() )  给类添加类属性 , 也可以直接这样  Test.age = 18 那给对象添加实例方法,可以在类外面 ...

  2. 39.VUE学习--组件,子组件中data数据的使用,x-template模板的使用,改变for循环里的某条数据里的值

    多处引用相同组件时,操作data不会相互影响 <!DOCTYPE html> <html> <head> <meta charset="utf-8& ...

  3. JAVA8新特性--集合遍历之forEach

    java中的集合有两种形式Collection<E>,Map<K,V> Collection类型集合 在JAVA7中遍历有一下几种方式:List<String> l ...

  4. python—— 文件的打开模式和文件对象方法 & os、os.path 模块中关于文件、目录常用的函数使用方法

    引用自“鱼c工作室”     文件的打开模式和文件对象方法  : https://fishc.com.cn/forum.php?mod=viewthread&tid=45279&ext ...

  5. POJ:3579-Median(二分+尺取寻找中位数)

    Median Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9201 Accepted: 3209 Description Gi ...

  6. [BZOJ1060][ZJOI2007]时态同步(树形DP)

    [我是传送门] 因为边权只能增加,那么设f[u]为u子树上从i出发到达某个叶节点的最大路径, 显然Ans应该增加f[u]-f[v]-e[i].w Code #include <cstdio> ...

  7. 理解canvas路径

    canvas路径和ps里面的路径差不多,在进行图形绘制时,先绘制出来图形的路径,然后再描边或者填充. canvas路径还有子路径的概念,在某一时刻,canvas之中只能有一条路径存在,Canvas规范 ...

  8. java跨服务器请求url获得数据

    在项目中,有时需要通过请求远程服务器上的url获取数据(前提是程序所在服务器可以和url服务器ping成功), 用java在后台发送请求时,用到了java.net.URL, java.net.URLC ...

  9. Android学习记录(9)—Android之Matrix的用法

    Matrix ,中文里叫矩阵,高等数学里有介绍,在图像处理方面,主要是用于平面的缩放.平移.旋转等操作. 首先介绍一下矩阵运算.加法和减法就不用说了,对应位相加就好.图像处理,主要用到的是乘法 .下面 ...

  10. JS——BOM、DOM

    BOM.DOM BOM window对象 history对象 location对象 screen对象 DOM DOM对HTML元素访问操作 HTML DOM树 DOM 节点 DOM访问HTML元素 D ...