POJ 3176 Cow Bowling
2016-04-17 09:11
513 查看
Cow Bowling
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.
动态规划
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 16639 | Accepted: 11089 |
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.
动态规划
#include <stdio.h> #include <string.h> int main() { int N, i, j; int dp[355][355]; scanf("%d", &N); memset(dp, 0, sizeof(dp)); for(i = 1; i <= N; i++) { for(j = 1; j <= i; j++) { scanf("%d", &dp[i][j]); } } for(i = N; i >= 1; i--) { for(j = 1; j <= i; j++) { dp[i][j] += dp[i + 1][j] > dp[i + 1][j + 1] ? dp[i + 1][j] : dp[i + 1][j + 1]; } } printf("%d\n", dp[1][1]); return 0; }
相关文章推荐
- POJ 1664 放苹果
- 从BlueSky.h和BlueSky.cpp到BlueSky.out的那些事儿
- C#单元测试面面观
- 《董福祥宫保府》后记
- SOAPUI笔记1: window安装
- POJ 3259 Wormholes
- Tech Blog
- 基于zookeeper应用——简单统一命名服务实现
- PHP垃圾回收机制
- 程序员必须要掌握的排序算法以及查找方法
- iOS之const,static,extern简介
- 项目内部IT/电商/信息化类简报,分享电子版
- MySql 数据库常用的sql语句
- Web安全测试之XSS
- 管道 && 消息队列 && 共享内存
- 对话吴恩达(Andrew Ng):超级大咖深度解析人工智能 以及如何成为已经数据挖掘工程师
- "Couldn't communicate with a helper application" in Xcode 7
- 第七周学习进度
- Eclipse中改变默认的workspace的方法及说明详解
- BZOJ 4206 转换之后求LIS