nyoj 18 The Triangle(数塔)
2015-09-23 20:08
309 查看
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 a[100][100]; int main(){ int n; while(scanf("%d",&n)!=EOF){ for(int i=1;i<=n;++i) for(int j=1;j<=i;++j){ scanf("%d",&a[i][j]); } for(int i=n-1;i>=1;--i){ for(int j=1;j<=i;++j){ if(a[i+1][j] > a[i+1][j+1]) a[i][j]+=a[i+1][j]; else a[i][j]+=a[i+1][j+1]; } } printf("%d\n",a[1][1]); } return 0; }
相关文章推荐
- 编程牛人的博客
- Codeforces Round #321 B Kefa and Company
- url链接在手机短信模块中显示问题
- C#访问MySQL数据库的方法
- JavaScript两种单例模式
- Java 猜数字小游戏
- LeetCode(86) Partition List
- iOS-程序发布-32位和64位系统的兼容
- nodejs、npm、grunt——名词解释
- hdu 2602--Bone Collector(01背包)
- FocusChange-焦点变化监听事件
- LeetCode(86) Partition List
- Ubuntu服务器安装mysql数据库
- 【DIV+CSS】代码作业练习DIV+CSS太极阴阳图
- “新建Laravel项目”并“开启laravel”的操作
- 安卓:WebView简单使用
- UVA592字符串推断题加暴力假设搜索
- AVS2高清实时编码器问世,性能大幅超越HEVC/H.265编码器x265
- leetcode刷题,总结,记录,备忘 118
- Altium Designer 14 安装完整元件库