博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj1163The Triangle(简单DP)
阅读量:5170 次
发布时间:2019-06-13

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

转载请注明出处:

题目链接:

----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋:
 
----------------------------------------------------------------------------------------------------------------------------------------------------------

Description

73   88   1   02   7   4   44   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

简单DP例如以下:

#include 
#include
using namespace std;int n;int dp[117][117];void DP(int dp[117][117]){ int i, j; for(i = n-1; i >= 0; i--) { for(j = 1; j <= i; j++) { dp[i][j]+=max(dp[i+1][j],dp[i+1][j+1]); } }}int main(){ int i, j; while(cin >> n) { for(i = 1; i <= n; i++) { for(j = 1; j <= i; j++) { cin>>dp[i][j]; } } DP(dp); cout<
<

转载于:https://www.cnblogs.com/hrhguanli/p/4560570.html

你可能感兴趣的文章
spring集成activeMq
查看>>
C语言基础
查看>>
在Linux环境下安装MYSQL
查看>>
bzoj2539: [Ctsc2000]丘比特的烦恼
查看>>
bzoj2958: 序列染色&&3269: 序列染色
查看>>
JDK常见问题 环境变量配置
查看>>
A Translation for Quaternion 一篇对四元数的翻译
查看>>
logging模块
查看>>
robotframework 接口测试 +RSA 加密
查看>>
bootstrap 预定义样式风格
查看>>
关于字节对齐(关于align)
查看>>
Java 避免创建不必要的对象
查看>>
升级Xcode8后需要添加的一些权限
查看>>
(学习日记)裘宗燕:C/C++ 语言中的表达式求值
查看>>
[Mongo] How to Install Mongo on Debian(不要安装)
查看>>
Redis-key的设计技巧
查看>>
break与continue关键字的使用
查看>>
postman 第4节 切换环境和设置读取变量(转)
查看>>
7-16 数据类型
查看>>
中级 PHP 知识点汇总
查看>>