POJ 3176 Cow Bowling(简单DP)
2015-12-16 14:29
337 查看
[align=center]Cow Bowling[/align]
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:
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
Sample Output
Hint
Explanation of the sample:
The highest score is achievable by traversing the cows as shown above.
题意:和HDOJ的数塔一模一样啦,从顶层部开始走,每一层取一个数,且必须以向正下方或者斜下方走,问走到底层,数字相加的和最大是多少。
代码如下:
[align=center]Cow Bowling[/align]
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 15952 | Accepted: 10626 |
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
5 7 3 8 8 1 0 2 7 4 4 4 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.
题意:和HDOJ的数塔一模一样啦,从顶层部开始走,每一层取一个数,且必须以向正下方或者斜下方走,问走到底层,数字相加的和最大是多少。
代码如下:
#include<cstdio> #include<cstring> int map[360][360]; int main() { int n,i,j; while(scanf("%d",&n)!=EOF) { for(i=0;i<n;++i) { for(j=0;j<=i;++j) scanf("%d",&map[i][j]); } for(i=n-2;i>=0;--i) { for(j=0;j<=i;++j) map[i][j]+=map[i+1][j]>map[i+1][j+1]?map[i+1][j]:map[i+1][j+1]; } printf("%d\n",map[0][0]); } return 0; }
相关文章推荐
- android应用Service和activity交互
- SubLime Text3 打造Python的IDE
- NSURLRequest 数据请求
- android 学习路线二
- 网站分析的一些东西(研究百度统计的方法和指标)
- Ubuntu:编译Linux内核源代码和内核模块
- git操作笔记
- Spring注入理解
- 【转载】Android 5.1 Art Hook 技术分享
- Linux下I2C驱动分析(二)
- 微信企业号开发七:JSAPI模式
- 一个简单的客户-服务器的Socket通信程序
- 02使用Maven构建Java项目
- loadrunner 脚本开发-参数化之将内容保存为参数、参数数组及参数值获取
- Android UI系列-----时间、日期、Toasts和进度条Dialog
- 大数据分享
- spring,IOC和AOP
- 创建oracle数据库的表空间、用户、目录、导入\导出文件等信息
- 圆角图片布局
- [机器学习]K邻近算法及其应用--WEKA工具