The Triangle

时间限制:1000 ms  |  内存限制:65535 KB
难度:4
描述

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.

输入
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.
输出
Your program is to write to standard output. The highest sum is written as an integer.
样例输入
5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
样例输出
30

其实就是一个简单的dp思想,每一步都去了最优值从而达到整体最优

代码

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[1010][1010],i,j,n,sum;
int main()
{
memset(a,0,sizeof(a));
sum=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
scanf("%d",&a[i][j]);
}
for(i=n-1;i>=1;i--)
{
for(j=1;j<=i*2-1;j++)
{
a[i][j]=max(a[i][j]+a[i+1][j],a[i][j]+a[i+1][j+1]);
}
}
printf("%d\n",a[1][1]);
return 0;
}


The Triangle--nyoj 18的更多相关文章

  1. NYOJ 18 The Triangle 填表法,普通dp

    题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=18 The Triangle 时间限制:1000 ms  |  内存限制:6553 ...

  2. nyoj 18 The Triangle

    The Triangle 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure ...

  3. Geometry and Appearances【转】

    https://github.com/AnalyticalGraphicsInc/cesium/wiki/Geometry-and-Appearances Geometry and Appearanc ...

  4. acdream.18.KIDx's Triangle(数学推导)

    KIDx's Triangle Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Sub ...

  5. nyoj 18-The Triangle(动态规划)

    18-The Triangle 内存限制:64MB 时间限制:1000ms Special Judge: No accepted:5 submit:5 题目描述: 7 3 8 8 1 0 2 7 4 ...

  6. NYOJ-102 次方求模 AC 分类: NYOJ 2014-02-06 18:53 184人阅读 评论(0) 收藏

    地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=102 //a^b mod c=(a mod c)^b mod c很容易设计出一个基于二分的递归 ...

  7. NYOJ-20 吝啬的国度 AC 分类: NYOJ 2014-01-23 12:18 200人阅读 评论(0) 收藏

    #include<cstdio> #include<cstring> #include<vector> using namespace std; int pre[1 ...

  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. 设计一个程序,程序中有三个类,Triangle,Lader,Circle。

    //此程序写出三个类,triangle,lader,circle:其中triangle类具有类型为double的a,b,c边以及周长,面积属性, //具有周长,面积以及修改三边的功能,还有判断能否构成 ...

  10. Think Python - Chapter 18 - Inheritance

    In this chapter I present classes to represent playing cards, decks of cards, and poker hands.If you ...

随机推荐

  1. 易企CMS主要模板文件介绍

    article.tpl 文章内容页模板 catalog.tpl 文章,产品目录页模板 category.tpl 分类页模板 comment.tpl 留言页模板 footer.tpl 页尾模板 head ...

  2. asp.net 后台注册脚本

    string myScript = "function ShowPanel() { $('.nav a[href=\"#" + PanelType.wenben.ToSt ...

  3. WinDbg使用

    1.抓dump文件 程序崩溃(crash)的时候, 为了以后能够调试分析问题, 可以使用WinDBG要把当时程序内存空间数据都保存下来,生成的文件称为dump 文件. 步骤: 1) 打开WinDBG并 ...

  4. fatal error C1083: 无法打开包括文件:“stdio.h

    现象: vs2012一直fatal error C1083: 无法打开包括文件:"stdio.h" 不知道配置太多,动到了什么地方,出现了这个问题: 在: 解决方案--调试源文件 ...

  5. <转>c++引用与指针的区别(着重理解)

     ★ 相同点: 1. 都是地址的概念: 指针指向一块内存,它的内容是所指内存的地址:引用是某块内存的别名.  ★ 区别: 1. 指针是一个实体,而引用仅是个别名: 2. 引用使用时无需解引用(*),指 ...

  6. Android 性能测试初探(五)

    书接上文 Android 性能测试初探之 GPU(四) 前文说了的一些性能测试项大家可能都听说,接下来我们聊聊大家不常关注的测试项- 功耗 . 功耗测试主要从以下几个方面入手进行测试 测试手机安装目标 ...

  7. 13、Next Item Recommendation with Self-Attention---自注意力+CML

    一.摘要: 自注意力机制------从用户历史交互中推断出项目-项目关系.学习每个项目的相对权重[用来学习用户的暂时兴趣表示] 二. 模型: 一部分是用于建模用户短期意图的自注意力机制,一部分是建模用 ...

  8. 【剑指Offer】19、顺时针打印矩阵

      题目描述:   输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下4 X 4矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依 ...

  9. NOIP2016 DAY2 T2蚯蚓

    传送门 Description 本题中,我们将用符号[c]表示对c向下取整,例如:[3.0」= [3.1」=[3.9」=3.蛐蛐国最近蚯蚓成灾了!隔壁跳 蚤国的跳蚤也拿蚯蚓们没办法,蛐蛐国王只好去请神 ...

  10. [luogu2317 HNOI2005] 星际贸易 (dp)

    传送门 Solution 两个dp分开处理, 第一问什么都不考虑直接dp 第二问还有些疑惑,姑且先留坑 Code //By Menteur_Hxy #include <cstdio> #i ...