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 ...
随机推荐
- fontconfig编译出错
编译fontconfig编译时出错: 出错configure: error: You must have freetype installed; see http://www.freetype.org ...
- BZOJ1012——[JSOI2008]最大数maxnumber
1.题目大意:求末尾L个数的最大值,强制在线 2.分析:这个拿线段树可以直接水过,然后我写了一个 维护单调栈, 二分求最大值的短代码,手懒.... #include <cstdio> #i ...
- JavaScript中的跨域
跨域是什么 跨域就是指从一个域名的网页去请求另一个域名的资源,因为JavaScript同源策略的限制,资源无法获取.比如从www.baidu.com 页面去请求 www.google.com 的资源, ...
- JS判断设备的类型
利用JS判断浏览器的用户代理,从而获得设备类型.利用这个方法可以获得用户的设备是移动设备还是PC设备. JS代码如下: function browerType() { ...
- gcc编译时对'xxxx'未定义的引用问题
gcc编译时对’xxxx’未定义的引用问题 gcc编译时对’xxxx’未定义的引用问题 原因 解决办法 gcc 依赖顺序问题 在使用gcc编译的时候有时候会碰到这样的问题,编译为.o(obj) 文件没 ...
- python的变量作用域问题
偶然掉进了一个坑里.仔细分析了下原因.原来是变量作用域的问题.简单抽象如下: id=1 #许多行代码 [id for id in range(10)] #许多行代码 if id!=1: #做一些事情 ...
- 怎样搭建PHP开发环境
搭建PHP开发环境首先第一步要 下载开发环境 wampserver 下载sublime text 2 sublime使用技巧 1:安装漂亮的编程字体http://pan.baidu.com/s/1xM ...
- 【Networkk】一篇文章完全搞清楚 scoket read/write 返回码、阻塞与非阻塞、异常处理 等让你头疼已久的问题
浅谈TCP/IP网络编程中socket的行为 我认为,想要熟练掌握Linux下的TCP/IP网络编程,至少有三个层面的知识需要熟悉: 1. TCP/IP协议(如连接的建立和终止.重传和确认.滑动窗 ...
- C++ 代码头注释模板
/********************************************************************************* *Copyright(C),You ...
- redis+crontab+php异步处理任务
2016年1月8日 16:08:43 星期五 情景: 用户登录日志, 发邮件, 发短信等等实时性要求不怎么高的业务通常会异步执行 之前接触过几种redis+crontab配套的实现方法, 比如: cr ...