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. [App Store Connect帮助]三、管理 App 和版本(1)添加 App 至您的帐户

    在向 App Store Connect 上传您 App 的构建版本之前,您必须先在您的 App Store Connect 帐户内新建一个 App. 如果您想将 iOS App 和 Apple TV ...

  2. 阿拉伯数字1与英语字母l造成的代码bug

    <img src="./images/demo3/1a.png" /> <img src="./images/demo3/la.png" /& ...

  3. --NSArray与NSMutableArray用copy修饰还是strong(转)

    一.NSMutableArray 被copy.strong修饰后的变化: 把NSMutableArray用copy修饰有时就会crash,因为对这个数组进行了增删改操作,而copy后的数组变成了不可变 ...

  4. ansible剧本

    yaml简介 YAML是"YAML Ain't a Markup Language"(YAML不是一种置标语言)的递归缩写,早先YAML的意思其实是:"Yet Anoth ...

  5. Winform中Treeview控件失去焦点,将选择的节点设置为高亮显示 (2012-07-16 13:47:07)转载▼

    Winform中Treeview控件失去焦点,将选择的节点设置为高亮显示 (2012-07-16 13:47:07)转载▼标签: winform treeview drawnode Treeview控 ...

  6. Java系列学习(一)-JDK下载与安装

    1.Java语言平台版本 J2SE:Java 2 Platform Standard Edition,java平台标准版 J2ME:Java 2 Platform Micro Edition,java ...

  7. Jupyter(Ipython) Notebook 入门

    upyter Notebook(此前被称为 IPython notebook)是一个交互式笔记本,支持运行 40 多种编程语言. 一般用来编写漂亮的交互式文档. 文学编程的读者不是机器,而是人. 我们 ...

  8. CSS——img

    img标签初始化:在低版本的ie浏览器会自带边框,所以建议border:0px.

  9. 11-c++虚拟函数

    虚拟函数 #include "stdio.h" class A{ public: void print() { printf("%s","this i ...

  10. tac

    功能说明:反向显示文件内容. 参数选项: -b 在行前而非行尾加分隔标志. -r 将分隔标志视作正则表达式来解析. -s 使用指定字符串代替换行作为分隔标志.   cat命令与tac命令的对比: