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
上传者
苗栋栋
 #include <stdio.h>

 int main()
{
int s[][]={};
int i,j,n;
int max=,t;
scanf("%d",&n);
for(i=;i<=n;i++)
{
for(j=;j<=i;j++)
{
scanf("%d",&s[i][j]);
t=(s[i-][j]>s[i-][j-])?s[i-][j]:s[i-][j-];
s[i][j]+=t;
}
}
for(i=;i<=n;i++)
if(s[n][i]>max)
max=s[n][i];
printf("%d\n",max);
//while(1);
return ;
}

//简单的动态规划

nyoj_18_The Triangle_201312071533的更多相关文章

随机推荐

  1. Flink之Window Operation

    目录 Configuring Time Characteristics Process Functions Window Operators Applying Functions on Windows ...

  2. Coursera Algorithms week4 基础标签表 练习测验:Inorder traversal with constant extra space

    题目原文: Design an algorithm to perform an inorder traversal of a binary search tree using only a const ...

  3. Android.mk添加第三方jar包(转载)

    转自:www.cnblogs.com/hopetribe/archive/2012/04/23/2467060.html LOCAL_PATH:= $(call my-dir)include $(CL ...

  4. PCB SQL SERVER 正则应用实例

    我们用过SQL SERVER的都知道,SQL SERVER它本身是不自带正则表达式的,因为没有,所以基本都没用过啊, 但我们在C#中对文本匹配用正则的方式处理非常好用,省得你写一堆代码实现匹配,多简洁 ...

  5. codevs2147数星星(哈希)

    2147 数星星  时间限制: 3 s  空间限制: 64000 KB  题目等级 : 钻石 Diamond   题目描述 Description 小明是一名天文爱好者,他喜欢晚上看星星.这天,他从淘 ...

  6. Oracle 10g RAC的负载均衡配置[转载]

    Oracle 10g RAC的负载均衡配置 负载均衡是指连接的负载均衡.RAC的负载均衡主要是指新会话连接到RAC数据库时,如何判定这个新的连接要连到哪个节点进行工作.在RAC中,负载均衡分为两种,一 ...

  7. EasyUI系列学习(二)-使用EasyUI

    一.引入必要文件 <!--1.0引入jQuery核心库--> <script src="jquery-easyui-1.4.4/jquery.min.js"> ...

  8. 【转】Java 集合系列09之 Map架构

    概要 前面,我们已经系统的对List进行了学习.接下来,我们先学习Map,然后再学习Set:因为Set的实现类都是基于Map来实现的(如,HashSet是通过HashMap实现的,TreeSet是通过 ...

  9. P1968 美元汇率

    题目背景 此处省略maxint+1个数 题目描述 在以后的若干天里戴维将学习美元与德国马克的汇率.编写程序帮助戴维何时应买或卖马克或美元,使他从100美元开始,最后能获得最高可能的价值. 输入输出格式 ...

  10. Android 串口驱动和应用测试

    这篇博客主要是通过一个简单的例子来了解Android的串口驱动和应用,为方便后续对Android串口服务和USB虚拟串口服务的了解.这个例子中,参考了<Linux Device Drivers& ...