博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[POJ] The Triangle
阅读量:7062 次
发布时间:2019-06-28

本文共 1250 字,大约阅读时间需要 4 分钟。

The Triangle
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 47278   Accepted: 28608

Description

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. 

Input

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.

Output

Your program is to write to standard output. The highest sum is written as an integer.

Sample Input

573 88 1 0 2 7 4 44 5 2 6 5

Sample Output

30

 

//利用动态规划解决问题#include
using namespace std;int a[101][101]; //二维数组储存三角形中的数int main(){ int n; cin>>n; for(int i=0;i
>a[i][j]; for(int i=n-2;i>=0;i--) for(int j=0;j<=i;j++) a[i][j]+=(a[i+1][j]>a[i+1][j+1]?a[i+1][j]:a[i+1][j+1]); //动态规划决策,从后往上加,加到最后最大值为顶端的值 cout<
<

  

转载于:https://www.cnblogs.com/KennyRom/p/6477084.html

你可能感兴趣的文章
SPI绿能宝与金沙江资本签署5亿美元可转债协议
查看>>
中英专家建言:未来城市发展要智慧化“留白”
查看>>
象棋中马行走路线的测试用例设计
查看>>
乌当区前三季度大数据产业实现产值60亿元
查看>>
可以拖动的弹出窗
查看>>
Tiny之Web工程构建
查看>>
android 的android httpClient详解
查看>>
IOS SEL的理解与使用
查看>>
iOS开发实用技巧—Objective-C中的各种遍历(迭代)方式
查看>>
iOS开发之SQLite--C语言接口规范(三)——Binding Values To Prepared Statements
查看>>
gdb 调试 sysbench
查看>>
Oracle官方并发教程之中断
查看>>
使用模板实现编译期间多态
查看>>
[置顶].NET平台开源项目速览(3)小巧轻量级NoSQL文件数据库LiteDB
查看>>
Cocos2D将v1.0的tileMap游戏转换到v3.4中一例(三)
查看>>
iOS Touch ID 简易开发教程
查看>>
结构体类型指针做函数参数(C++)
查看>>
Akka笔记之消息传递
查看>>
带你实现开发者头条(一) 启动页实现
查看>>
Android Listview中Button按钮点击事件冲突解决办法
查看>>