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

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

Cow Bowling
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 21242   Accepted: 14046

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
;using namespace std;const int maxn = 355;int n,mark,cows[2][maxn];void solve(){ scanf("%d",&n); scanf("%d",&cows[0][0]); for(int i = 2;i <= n;i++){ mark = (i - 1) % 2; for(int j = 0;j < i;j++) scanf("%d",&cows[mark][j]); //两端 cows[mark][0] += cows[1-mark][0]; cows[mark][i-1] += cows[1-mark][i-2]; //中间 for(int j = 1;j < i - 1;j++){ cows[mark][j] += max(cows[1-mark][j-1],cows[1-mark][j]); } } int highest = 0; for(int i = 0;i < n;i++){ if(cows[mark][i] > highest) highest = cows[mark][i]; } printf("%d\n",highest);}int main(){ solve(); return 0;}

转载于:https://www.cnblogs.com/JingwangLi/p/10202792.html

你可能感兴趣的文章
Mangos魔兽世界服务端初探(1)--游戏服务端主体结构与消息分发
查看>>
SonarQube svn 认证失败的解决办法
查看>>
C++string与VC++CString互转
查看>>
Ubuntu查找占用端口进程并删除
查看>>
Rgb to Yuv,Tuv to Rgb转换(C# emgucv)
查看>>
JSTL标签+EL表达式
查看>>
PHP中的java方式重载
查看>>
CSS3:RESET、标准注释、多屏幕尺寸兼容写法。
查看>>
小得瑟一下,记一下一个SQL语句
查看>>
uCLinux上UCD-SNMP Agent的实现
查看>>
在线时序图工具推荐
查看>>
改进的难度 产品经理
查看>>
Redis replication
查看>>
Android TextView 高度问题
查看>>
Android 热补丁动态修复框架小结
查看>>
轻量级消息队列
查看>>
osx分区合并命令行操作
查看>>
使用yii里面的module碰到的小问题
查看>>
JQuery Slider 实现时间刻度滑动条,用以编辑项目/起始时间(手动输入可自动更新到滑动条)...
查看>>
精确测量小信号的示波器及探头技术
查看>>