博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 3176 Cow Bowling
阅读量:4515 次
发布时间:2019-06-08

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

Description

The cows don't use actual bowling balls when they go bowling. They each take a number (in the range 0..99), though, and line up in a standard bowling-pin-like triangle like this: 
7         3   8       8   1   0     2   7   4   4   4   5   2   6   5
Then the other cows traverse the triangle starting from its tip and moving "down" to one of the two diagonally adjacent cows until the "bottom" row is reached. The cow's score is the sum of the numbers of the cows visited along the way. The cow with the highest score wins that frame. 
Given a triangle with N (1 <= N <= 350) rows, determine the highest possible sum achievable.

Input

Line 1: A single integer, N 
Lines 2..N+1: Line i+1 contains i space-separated integers that represent row i of the triangle.

Output

Line 1: The largest sum achievable using the traversal rules

Sample Input

573 88 1 02 7 4 44 5 2 6 5

Sample Output

30

Hint

Explanation of the sample: 
7          *         3   8        *       8   1   0        *     2   7   4   4        *   4   5   2   6   5
The highest score is achievable by traversing the cows as shown above.

Source

基础动态规划,每个数可以加到他下方相邻的两个数上,如此每个数可以加上上方相邻的两个数,选择大的那个。最后选择最大的。
代码:
#include 
#include
#include
#include
#include
#include
#define MAX 351#define inf 0x3f3f3f3fusing namespace std;int n;int s[MAX][MAX];int main() { scanf("%d",&n); for(int i = 1;i <= n;i ++) { for(int j = 1;j <= i;j ++) { scanf("%d",&s[i][j]); s[i][j] += max(s[i - 1][j],s[i - 1][j - 1]); } } int ans = 0; for(int i = 1;i <= n;i ++) { ans = max(ans,s[n][i]); } printf("%d",ans);}

 

转载于:https://www.cnblogs.com/8023spz/p/9522817.html

你可能感兴趣的文章
类与方法
查看>>
Python学习笔记(九) map、zip和filter函数
查看>>
吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-plus-sign...
查看>>
吴裕雄--天生自然 JAVASCRIPT开发学习:比较 和 逻辑运算符
查看>>
html 存放PDF文档
查看>>
setTimeout 传参
查看>>
PC客户端开发细节记录:保存GUID到VARIANT
查看>>
day5感想
查看>>
给DEDE织梦CMS添加搜索结果页显示自定义字段
查看>>
第二章 第五节 获取帮助
查看>>
分布式监控系统Zabbix-3.0.3-完整安装记录(0)
查看>>
关于源代码及其管理工具的总结
查看>>
此文对你人生会有莫大好处的,建议永久保存 2013-07-26 11:04 476人阅读 评论(0) ...
查看>>
win10 压缩包安装mysql8.0.11报错:Access denied for user 'root'@'localhost'
查看>>
随笔:关于去年的WordPress建站的回忆
查看>>
iptables配置——NAT地址转换
查看>>
vue----生命周期
查看>>
tornado ThreadPoolExecutor
查看>>
类里的方法要不要加参数
查看>>
C#毫秒转时分秒格式
查看>>