POJ 3176 Cow Bowling (简单DP)
来源:互联网 发布:斗牛牛软件下载 编辑:程序博客网 时间:2024/05/29 03:21
Cow Bowling
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 12503 Accepted: 8250
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:
Given a triangle with N (1 <= N <= 350) rows, determine the highest possible sum achievable.
7 3 8 8 1 0 2 7 4 4 4 5 2 6 5Then 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.
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 5The highest score is achievable by traversing the cows as shown above.
Source
USACO 2005 December Bronze
#include <cstring>#include <cstdio>#include<algorithm> using namespace std;const int maxv = 355;int vis[maxv][maxv],map[maxv][maxv],n;int getMax(int i, int j){ if(i==n) return vis[i][j]=map[i][j]; if(vis[i][j]!=-1) return vis[i][j]; return vis[i][j]=map[i][j]+max(getMax(i+1,j), getMax(i+1,j+1));}int main(){ memset(vis,-1,sizeof(vis)); scanf("%d", &n); for(int i=1; i<=n; i++) for(int j=1; j<=i; j++) scanf("%d", &map[i][j]); printf("%d\n",getMax(1,1));}
递归
#include <cstdio>#include <algorithm>using namespace std;int main(){ const int maxv = 355; int map[maxv][maxv],n; scanf("%d",&n); for(int i=1; i<=n; i++) for(int j=1; j<=i; j++) scanf("%d",&map[i][j]); for(int i=n-1; i>=1; i--){ for(int j=1; j<=i; j++) map[i][j] += max(map[i+1][j], map[i+1][j+1]); } printf("%d\n",map[1][1]);}
- POJ 3176 Cow Bowling (简单DP)
- POJ 3176 Cow Bowling (简单DP)
- POJ 3176-Cow Bowling (简单DP)
- POJ 3176 Cow Bowling (简单DP)
- POJ 3176 Cow Bowling(简单DP)
- POJ-3176-Cow Bowling-(简单dp)
- POJ 3176 Cow Bowling DP
- poj-3176-Cow Bowling-dp
- poj 3176 Cow Bowling (DP)
- poj 3176 Cow Bowling dp
- POJ 3176 Cow Bowling DP
- poj 3176Cow Bowling DP
- Poj 3176 Cow Bowling【dp】
- POJ 3176 Cow Bowling (dp)
- POJ-3176 Cow Bowling 数塔,简单DP
- poj 3176 Cow Bowling(最简单DP题)
- poj 3176 -- Cow Bowling (dp)
- poj 3176 Cow Bowling 数塔dp
- ubuntu安装Hadoop-1.2.1
- Object9
- JAVA规则引擎 -- Drools
- 内部类与匿名内部类
- Effective Objective-C 2.0: Item 29: Understand Reference Counting
- POJ 3176 Cow Bowling (简单DP)
- 异常11
- Jeecg Tag的扩展参数,及其虚拟布局
- Working Practice-表达代码的方法
- Drools5集成Spring3
- Codeforces Round #218 (Div. 2)
- FairScheduler的任务调度机制——assignTasks
- HDU 2049 不容易系列之(4)——考新郎 (错排)
- Cloudera Hue Issues