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. (转) 前端模块化:CommonJS,AMD,CMD,ES6

    模块化的开发方式可以提高代码复用率,方便进行代码的管理.通常一个文件就是一个模块,有自己的作用域,只向外暴露特定的变量和函数.目前流行的js模块化规范有CommonJS.AMD.CMD以及ES6的模块 ...

  2. 使用T-sql建库建表建约束

    为什么要使用sql语句建库建表? 现在假设这样一个场景,公司的项目经过测试没问题后需要在客户的实际环境中进行演示,那就需要对数据进行移植,现在问题来了:客户的数据库版本和公司开发阶段使用的数据库不兼容 ...

  3. Caffe: Vs13添加CUDA支持

    1.  右键工程 点击:Building Dependency 右击:Build Customizations 点击选项:CUDA 7.5 2.添加C++依赖: cudart.lib kernel32 ...

  4. Git及Github环境搭建(Windows系统)

    一.github账号注册 1.打开网址https://github.com  注册账号: 二.本地安装Git 1.安装包下载地址:链接:https://pan.baidu.com/s/1smpnJL7 ...

  5. 插入DOM元素

    插入Dom元素两种情况: 1.要插入的元素是从页面中获取的dom结构 ,例如:$(".item") 2.要插入的元素是通过变量存储的dom结构,例如:var html = &quo ...

  6. 团体程序设计天梯赛-练习集-L1-032. Left-pad

    L1-032. Left-pad 根据新浪微博上的消息,有一位开发者不满NPM(Node Package Manager)的做法,收回了自己的开源代码,其中包括一个叫left-pad的模块,就是这个模 ...

  7. PAT_A1078#Hashing

    Source: PAT A1078 Hashing (25 分) Description: The task of this problem is simple: insert a sequence ...

  8. 51Nod - 1134 最长递增子序列【动态规划】

    给出长度为N的数组,找出这个数组的最长递增子序列.(递增子序列是指,子序列的元素是递增的) 例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10. Input 第1行:1个数N ...

  9. 38.mapping小例子

    主要知识点 初步了解mapping     一,准备数据 插入几条数据,让es自动为我们建立一个索引     PUT /website/article/1 { "post_date" ...

  10. 解决ExpressSpreadSheet 中文乱码问题[备查]

    cxSpreadSheet和F1Book等都提供了类似Excel的操作, 但是相比F1Book, cxSpreadSheet的中文支持还不是很完善.在设置了wordbreak为true的时候,里面的中 ...