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>
#include<string.h>
int max(int a, int b){
return (a>b)?a:b;
}
int main()
{
int n;
][];
][];
scanf("%d", &n);
;
; i < n; ++i) {
; j < i+; ++j) {
arr[i][j] = sumdpth[i][j] = ;
scanf("%d", &arr[i][j]);
sumdpth[i][j] = arr[i][j];
}
}
; i < n; ++i) {
; j < i+; ++j) {
){
sumdpth[i][j] = arr[i-][j];
}
sumdpth[i][j] = max(sumdpth[i-][j]+arr[i][j],sumdpth[i-][j-]+arr[i][j]) ;
if(tmpmax < sumdpth[i][j]) tmpmax = sumdpth[i][j];
}
}
printf("%d\n", tmpmax);
/*
for (int i = 0; i < n; ++i) {
for (int j = 0; j < i+1; ++j) {
printf("%d ", arr[i][j]);
}
printf("\n");
}
*/
}
The Triangle的更多相关文章
- [LeetCode] Triangle 三角形
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- [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, ...
- [LeetCode] Pascal's Triangle 杨辉三角
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 【leetcode】Pascal's Triangle II
题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...
- 【leetcode】Pascal's Triangle
题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...
- POJ 1163 The Triangle(简单动态规划)
http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- Triangle - Delaunay Triangulator
Triangle - Delaunay Triangulator eryar@163.com Abstract. Triangle is a 2D quality mesh generator an ...
- LeetCode 118 Pascal's Triangle
Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows ...
- LeetCode 119 Pascal's Triangle II
Problem: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Ret ...
- 【leetcode】Triangle (#120)
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
随机推荐
- Linux下查看nginx安装目录
输入命令行: ps -ef | grep nginx master process后边的目录即是.
- js分页--存储数据并进行分页
//分页方法 var page = function(){ this.v = { o:null,//ul父级层 home:null, previous:null, next:null, last:nu ...
- 全架构PaaS TAE 2.0的Docker实践
推荐链接: http://www.infoq.com/cn/news/2015/07/paas-tae-docker
- 微软“One Windows”的梦想已经破灭了吗?
导读 Windows 10 正式公布的时候,微软曾表示该系统将开启更为个性化的计算新纪元,可让用户在使用各类设备处理各项事务时,享受到一致.熟悉和可兼容的体验,从 Xbox 到 PC 和手机,再到平板 ...
- linux各文件夹的作用
文章转载自:http://www.cnblogs.com/amboyna/archive/2008/02/16/1070474.html 精------------------------------ ...
- union联合体
今天笔试的一道题,好久没用union了,竟然忘光光了. 关于其大小的计算,分两步:先算对齐大小(成员中字节最大的那个),再算分配空间: 不仅是对齐大小的整数倍,还要满足实际大小不能小于最大成员大小. ...
- trac中wiki直接显示任务代码
= 我的任务 = [[TicketQuery(max=10,owner=$USER, status!=closed|verified|cancelled, order=id,desc=1,format ...
- 如何优雅的使用 phpStorm 开发工具
按照惯例依然是从百科上复制一条简介: PhpStorm 是 JetBrains 公司开发的一款商业的 PHP 集成开发工具.PhpStorm可随时帮助用户对其编码进行调整,运行单元测试或者提供可视化d ...
- devstack两次以上重装提高成功率的方法
1) /opt/stack/requirements/ git reset --hard 2) rm -rf /usr/local/lib/python2.7/dist-packages/*
- openstack 常用命令
转自: docs.openstack.org $ nova boot --image ubuntu-cloudimage --flavor 1 --user-data mydata.file