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 ...
随机推荐
- mongodb certification
又偷懒 也有学到不少东西 这个东西算是小结啦 给2013年的碌碌无为挽回点面子 哈哈~
- Android开源项目(二)
第二部分 工具库 主要包括那些不错的开发库,包括依赖注入框架.图片缓存.网络相关.数据库ORM建模.Android公共库.Android 高版本向低版本兼容.多媒体相关及其他. 一.依赖注入DI 通过 ...
- iOS开发——UI基础-Xcode资源拷贝
#1.拷贝资源的时候选择的copy的含义: 是否要将资源拷贝一份到项目中, 如果不勾选就代表着不拷贝, 那么原来的资源不见了, 项目中的也不能用了 注意: 1.虽然项目中的图片和外部的图片是同一张图片 ...
- Java序列化技术与Protobuff
http://www.cnblogs.com/fangfan/p/4094175.html http://www.cnblogs.com/fangfan/p/4094175.html 前言: Java ...
- Unity手游之路<十>自动寻路Navmesh之跳跃,攀爬,斜坡
http://blog.csdn.net/janeky/article/details/17598113 在之前的几篇Blog总,我们已经系统学习了自动寻路插件Navmesh的相关概念和细节.然而,如 ...
- TortoiseSVN使用方法
1.初始化本地SVN目录,在某个文件夹鼠标右键点击. 初始化后目录 2.将某个目录下代码,添加到SVN目录中. 3.将添加进去代码提取出来. 在某 ...
- 修改vb程序图标
1. 2.
- css position属性
absolute, 屏幕为参照, 但固定在页面上,随页面滚动而动. fixed, 父元素没有指定position属性(或position属性为static时)==>屏幕为参照,固定在屏幕的某个位 ...
- gjd
#include <cstdio> #include <cstring> #include <malloc.h> #define radix (1u<< ...
- Python读取中文txt文件错误:UnicodeEncodeError: 'gbk' codec can't encode character
with open(file,'r') as f: line=f.readline() i=1 while line: line=line.decode('utf-8') line=f.readlin ...