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 ...
随机推荐
- 数据库调优过程(二):找到IO不存在问题,而是sqlserver单表写入IO瓶颈
物理机上测试IO是否为瓶颈: 使用一个死循环insert into测试数据库最大写入速度: use [iTest]; declare @index int; ; begin ; INSERT into ...
- 不等高cell的tableView界面搭建
一.搭建界面 1.界面分析 分析界面的层次结构,分析界面应该用什么控件来搭建 2.界面层次结构 分析之后,我们可以把这个界面分为四个模块(topView middleView commentView ...
- Codeforce Round #228 Div2
这次的A题没注意要到100- -, B题没做,后来做要注意下1和long long C题当时坑的一B,用了个蠢办法,后来还错了,现在改了,还是蠢办法,等等再去用dp吧,而且本来就只有01用个鸡巴的树状 ...
- C++多线程调试和测试的注意事项
在一个程序中,这些独立运行的程序片断叫作“线程”(Thread),利用它编程的概念就叫作“多线程处理”.利用线程,用户可按下一个按钮,然后程序会立即作出响应,而不是让用户等待程序完成了当前任务以后才开 ...
- cookie的保存时间
使用 .setMaxAge()设置(单位是秒) second>0 保存在硬盘上的时间 second<0 默认保存在浏览器的内存中 second=0 立即删除
- 部署ganglia3.7
环境 centOS6.6 gmetad节点关闭iptable gmetad和httpd只需要在一台节点安装,gmond需要在每台节点上安装. 一.安装epel源 sudo wget http://do ...
- 夺命雷公狗—angularjs—24—extend继承对象
我们的angularjs中也是给我们留下了方法来做继承的,那么他就是传授中的extend... 不过要如下所示,第二个参数是继承到第一个对象里面的... <!DOCTYPE html> & ...
- WebService优点和缺点小结(转)
一.什么是WebService? 实际上,WebService的主要目标是跨平台的可互操作性.为了达到这一目标,WebService完全基于XML(可扩展标记语言).XSD (XMLSchema) ...
- 项目中的一个JQuery ajax实现案例
/** * brief 这些代码用于在线制图中 attention author <list of authors> <date> begin modify by * nu ...
- Spring MVC 和 Spring 总结
1. 为什么使用Spring ? 1). 方便解耦,简化开发 通过Spring提供的IoC容器,可以将对象之间的依赖关系交由Spring进行控制,避免硬编码所造成的过度程序耦合. 2). AOP编程的 ...