nyoj_18_The Triangle_201312071533
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 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的更多相关文章
随机推荐
- Flink编程练习
目录 1.wordcount 2.双流警报EventTime 3.持续计数stateful + timer + SideOutputs 4.一定时间范围内的极值windowfunction + che ...
- E20170925-hm
arc n. 综合症状; 弧(度); 天穹; 电弧,弧光.; vi. 形成拱状物; 循弧线行进; wrap vt. 包; 缠绕; 用…包裹(或包扎.覆盖等); 掩护; n. ...
- E20170627-hm
confirmation n. 证实; 证明; 确认,
- 关于CSS中float的两点心得以及清除浮动的总结
对一个元素运用float后,该元素将脱离正常文档流,这意味着: 1. 运用float后,该元素不再影响父元素的高度,如果一个元素的所有子元素都是float的话,那么该元素的高度是0,这样后面元素渲染的 ...
- tp 3.2 组合查询, 字符串模式查询
$User = M("User"); // 实例化User对象 $map['id'] = array('neq',1); $map['name'] = 'ok'; $map['_s ...
- Spring思维课程导图——bean得实例化和bean的管理
- define与typedef的区别
define: 发生在预处理阶段,也就是编译之前,仅仅文本替换,不做任何的类型检查 没有作用域的限制 typedef: 多用于简化复杂的类型声明,比如函数指针声明:typedef bool (*fun ...
- Offer收割_4
1.水题 2.BFS宽搜(使用优先队列priority_queue) 4.题意:给数组a.要求重排列数组,使得数组中的任意相邻的两个元素不同.如果存在多个方案,那么选择字典序最小的方案. 如果不能满 ...
- 函数 out 传值 分割
public void Jia(int a ,int b) { a = a + b; Console.WriteLine(a); } public void Jia1(int a,out int b) ...
- eclipse整合maven下载jar包速度慢问题解决
引用:http://blog.csdn.net/u010154380/article/details/70339538 开发过程中在pom.xml中添加pom的时候,默认是需要从中央仓库中下载,但是下 ...