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. VMWARE修改CPUID

    在cmd shell下执行wmic cpu get ProcessorId命令,可是查看机器的cpuID,但这个命令显示的只是2组ID,实际CPUID,有4组 通过更改虚拟机配置文件.vmx可是实现任 ...

  2. MMAP和DIRECT IO区别

    看完此文,题目不言自明.转自 http://blog.chinaunix.net/uid-27105712-id-3270102.html 在Linux 开发中,有几个关系到性能的东西,技术人员非常关 ...

  3. MATLAB求解代数方程、微分方程的一些常用指令

    MATLAB版本:R2015b 1.求解符号矩阵的行列式.逆.特征值.特征向量 A = sym('[a11, a12; a21, a22]');deltaA = det(A)invA = inv(A) ...

  4. LInux Shell 快捷键

    CTRL 键相关的快捷键: Ctrl + a - Jump to the start of the lineCtrl + b - Move back a charCtrl + c - Terminat ...

  5. sublime如何自动保存

    sublime是前端开发者喜欢使用的工具,它有很多快捷方式可以让我们快速的编写代码:在开发过程中,每次修改代码之后都要按Ctrl+S保存.在这里向大家介绍一下如何设置让它自动保存. 一.打开subli ...

  6. taskkill批量删除进程命令

    本人自用: TASKKILL /F /IM notepad --强制删除进程名中带notepad的所有进程 TASKKILL [/S system [/U username [/P [password ...

  7. zTree和SweetAlert插件初探

    1.zTree插件简介 zTree是一个依靠 jQuery实现的多功能“树插件”.优异的性能.灵活的配置.多种功能的组合是zTree最大优点.专门适合项目开发,尤其是树状菜单.树状数据的Web显示.权 ...

  8. winform快速开发平台->让有限的资源创造无限的价值!

    最近一直在维护一套自己的快速开发平台. 主要应对针对C/S架构下的项目.然而对winform这快,还真没有看到过相对好的快速开发平台, 何为快速,在博客园逛了了好久, 预览了很多通用权限管理系统. 确 ...

  9. ROS学习(一)—— 环境搭建

    一.配置Ubuntu软件仓库且选择ROS正确版本 二.添加source.list sudo sh -c 'echo "deb http://packages.ros.org/ros/ubun ...

  10. 加密狗的管理层API(C#代码)

    using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServi ...