http://poj.org/problem?id=1163

The Triangle
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 32923   Accepted: 19514

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

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page   Go Back  To top

简单的动态规划。。。

 By LFENG
 
#include<stdio.h>
int main()
{
    int a[][];
    int n,i,j;
    scanf("%d",&n);
    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]+=(a[i+][j]>a[i+][j+])?a[i+][j]:a[i+][j+];
    printf("%d\n",a[][]);
    return ;
}

POJ 1163 The Triangle(简单动态规划)的更多相关文章

  1. POJ 1163 The Triangle 简单DP

    看题传送门门:http://poj.org/problem?id=1163 困死了....QAQ 普通做法,从下往上,可得状态转移方程为: dp[i][j]= a[i][j] + max (dp[i+ ...

  2. POJ - 1163 The Triangle 【动态规划】

    一.题目 The Triangle 二.分析 动态规划入门题. 状态转移方程$$DP[i][j] = A[i][j] + max(DP[i-1][j], DP[i][j])$$ 三.AC代码 1 #i ...

  3. poj 1163 The Triangle &amp;poj 3176 Cow Bowling (dp)

    id=1163">链接:poj 1163 题意:输入一个n层的三角形.第i层有i个数,求从第1层到第n层的全部路线中.权值之和最大的路线. 规定:第i层的某个数仅仅能连线走到第i+1层 ...

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

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

  5. OpenJudge/Poj 1163 The Triangle

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

  6. POJ 1163 The Triangle(经典问题教你彻底理解动归思想)

    The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 38195   Accepted: 22946 De ...

  7. The Triangle (简单动态规划)

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

  8. poj 1163 The Triangle

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

  9. Poj 1163 The Triangle 之解题报告

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

随机推荐

  1. css3-columns多列布局

    /*css3中的布局*/ .wrapper{ margin:auto; width:300px; height:200px; border:2px dotted blue; -webkit-colum ...

  2. hibernate整合spring事务异常

    Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushM ...

  3. 重建索引提高SQL Server性能

    大多数SQL Server表需要索引来提高数据的访问速度,如果没有索引,SQL Server 要进行表格扫描读取表中的每一个记录才能找到索要的数据.索引可以分为簇索引和非簇索引,簇索引通过重排表中的数 ...

  4. NPA——.NET Persistence API

    你可曾听说过JPA. 有JPA那么就一定有NPA. 软件架构的路上一定少不了这个名词. —————————————————————————————————————————————— P Persist ...

  5. cxf webservice 生成wsdl方法参数名称为arg0问题

    在通过cxf生成webservice服务时,如果你是用ServerFactoryBean,那么在生成wsdl时,方法的参数名称会被自动命名为arg0,arg1...,如: <xsd:comple ...

  6. 修改一个CGRect的值

    // 1. 用一个临时变量保存返回值. CGRect temp = self.view.frame; // 2. 给这个变量赋值. temp.size.width = kWIDTH; // 3. 修改 ...

  7. Guava学习笔记(一)概览

    Guava是谷歌开源的一套Java开发类库,以简洁的编程风格著称,提供了很多实用的工具类, 在之前的工作中应用过Collections API和Guava提供的Cache,不过对Guava没有一个系统 ...

  8. 【React】Stateless Function

    React创建组件的时候,有3种写法: // 1. 传统写法 const App = React.createClass({}); // 2. es6 的写法 class App extends Re ...

  9. Java并发集合的实现原理

    本文简要介绍Java并发编程方面常用的类和集合,并介绍下其实现原理. AtomicInteger 可以用原子方式更新int值.类 AtomicBoolean.AtomicInteger.AtomicL ...

  10. UVALive 2453 Wall (凸包)

    题意:给你一个多边形的城堡(多个点),使用最短周长的城墙将这个城堡围起来并保证城墙的每个点到城堡上的每个点的距离都不小于l 题解:因为两点间的直线一定比折线短,所以这样做 先使用所有点求得一个凸包,接 ...