Cow Bowling
Cow Bowling
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 15585 Accepted: 10363
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
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.
Source
USACO 2005 December Bronze
简单DP;
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MAX = 1100;
int a[400][400];
int n;
int main()
{
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
scanf("%d",&a[i][j]);
}
}
for(int i=n-1;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
a[i][j]+=max(a[i+1][j],a[i+1][j+1]);
}
}
printf("%d\n",a[1][1]);
}
return 0;
}
Cow Bowling的更多相关文章
- POJ 3176 Cow Bowling
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13016 Accepted: 8598 Desc ...
- POJ3176——Cow Bowling(动态规划)
Cow Bowling DescriptionThe cows don't use actual bowling balls when they go bowling. They each take ...
- POJ 3176:Cow Bowling
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13464 Accepted: 8897 Desc ...
- POJ3176 Cow Bowling 2017-06-29 14:33 23人阅读 评论(0) 收藏
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19173 Accepted: 12734 Des ...
- POJ 3176 Cow Bowling(dp)
POJ 3176 Cow Bowling 题目简化即为从一个三角形数列的顶端沿对角线走到底端,所取得的和最大值 7 * 3 8 * 8 1 0 * 2 7 4 4 * 4 5 2 6 5 该走法即为最 ...
- 【POJ 3176】Cow Bowling
题 Description The cows don't use actual bowling balls when they go bowling. They each take a number ...
- poj 3176 Cow Bowling(dp基础)
Description The cows don't use actual bowling balls when they go bowling. They each take a number (i ...
- 杭电三部曲一、基本算法;19题 Cow Bowling
Problem Description The cows don't use actual bowling balls when they go bowling. They each take a n ...
- Poj3176 Cow Bowling (动态规划 数字三角形)
Description The cows don't use actual bowling balls when they go bowling. They each take a number (i ...
随机推荐
- ${pageContext.request.contextPath} JSP取得绝对路径
一.问题 JSP中究竟采用绝对路径还是采用相对路径随着所采用技术的越来越复杂,这个问题也变得越来越难以解决. 1)采用相对路径遇到的问题 相对路径固然比较灵活,但如果想复制页面内的代 ...
- linux 命令之 insmod
man insmod: INSMOD(8) insmod INSMOD(8) NAME insmod - Simple program to insert a module into the Linu ...
- (转)flexigrid 参数说明
本文为转载 http://simple1024.iteye.com/blog/1171090 项目用到这玩意,像样的API都是英文的,英文不好,所以经过各种搜集,flexigrid就整理了这么多用得上 ...
- zjuoj 3610 Yet Another Story of Rock-paper-scissors
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3610 Yet Another Story of Rock-paper-sc ...
- linux下忘记mysql root密码解决办法
vi /etc/my.cnf #编辑文件,找到[mysqld],在下面添加一行skip-grant-tables [mysqld] skip-grant-tables :wq! #保存退出 s ...
- paper 78:sniff抓包程序片段
#define INTERFACE "eth0"#define MAX_SIZE 65535 int init_raw_socket();int open_promisc(char ...
- paper 40 :鲁棒性robust
最近只想安心.安静的科研,不想被任何人打扰,继续做自己,不忘初心,方得始终! 首先了解下鲁棒性这个词的定义.鲁棒性是指控制系统在一定(结构,大小)的参数摄动下,维持某些性能的特性.根据对性能的不同定义 ...
- oracle表分区
注:新建分区表前要先准备好要用的表空间 一. oracle分区类型: 范围分区(Range分区) 列表分区(List分区) 散列分区(Hash分区) 组合分区(Composite Partitioni ...
- PAT乙级 1002. 写出这个数 (20)
1002. 写出这个数 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 读入一个自然数n,计算其各位数字 ...
- 【转】转换到 COFF 期间失败: 文件无效或损坏
不知怎么本来编译好好的VS2010环境,忽然出现“转换到 COFF 期间失败: 文件无效或损坏”的链接错误.花了好多天,试了好多方法,最终解决了这个问题. 现在罗列一下这几种解决方案: 方案1 ...