Cow Bowling
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 13464   Accepted: 8897

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.

简单的数塔DP问题。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream> using namespace std; const int M = 350 +5;
int Cow[M][M]; int main()
{
int n;
while(scanf("%d", &n)!=EOF)
{
memset(Cow, 0, sizeof(Cow));
for(int i=1; i<=n; i++)
for(int j=1; j<=i; j++)
{
scanf("%d", &Cow[i][j]);
}
for(int i=n-1; i>=1; i--)
for(int j=1; j<=i; j++)
Cow[i][j]+=max(Cow[i+1][j], Cow[i+1][j+1]);
cout<<Cow[1][1]<<endl;
} return 0;
}

POJ 3176:Cow Bowling的更多相关文章

  1. 【POJ 3176】Cow Bowling

    题 Description The cows don't use actual bowling balls when they go bowling. They each take a number ...

  2. 【POJ 3176】Cow Bowling(DP)

    题 Description The cows don't use actual bowling balls when they go bowling. They each take a number ...

  3. POJ 3673:Cow Multiplication

    Cow Multiplication Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12210   Accepted: 85 ...

  4. POJ 2184:Cow Exhibition(01背包变形)

    题意:有n个奶牛,每个奶牛有一个smart值和一个fun值,可能为正也可能为负,要求选出n只奶牛使他们smart值的和s与fun值得和f都非负,且s+f值要求最大. 分析: 一道很好的背包DP题,我们 ...

  5. POJ 3176 Cow Bowling(dp)

    POJ 3176 Cow Bowling 题目简化即为从一个三角形数列的顶端沿对角线走到底端,所取得的和最大值 7 * 3 8 * 8 1 0 * 2 7 4 4 * 4 5 2 6 5 该走法即为最 ...

  6. poj 1163 The Triangle &amp;poj 3176 Cow Bowling (dp)

    id=1163">链接:poj 1163 题意:输入一个n层的三角形.第i层有i个数,求从第1层到第n层的全部路线中.权值之和最大的路线. 规定:第i层的某个数仅仅能连线走到第i+1层 ...

  7. POJ 3176 Cow Bowling

    Cow Bowling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13016   Accepted: 8598 Desc ...

  8. POJ 3176 简单DP

    Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16448 Accepted: 10957 Descrip ...

  9. POJ 3617 Best Cow Line(最佳奶牛队伍)

    POJ 3617 Best Cow Line Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] FJ is about to t ...

随机推荐

  1. python使用libssh2连接linux

    1.安装(1)使用下面命令获得最新版本的ssh4py安装包    git clone git://github.com/wallunit/ssh4py (2)解压ssh4py后使用下面命令进行安装: ...

  2. bzoj 1901: Zju2112 Dynamic Rankings(树套树)

    1901: Zju2112 Dynamic Rankings 经典的带改动求区间第k小值问题 树套树模板,我是用的线段树套splay实现的,并且用的数组模拟的,所以可能空间略大,bzoj过了,zoj过 ...

  3. 使用 HTML5 webSocket API实现即时通讯的功能

    project下载地址:http://download.csdn.net/detail/wangshuxuncom/6430191 说明: 本project用于展示怎样使用 HTML5 webSock ...

  4. IT忍者神龟之Oracle DBA经常使用查询吐血列举

    –1. 查询系统全部对象 select owner, object_name, object_type, created, last_ddl_time, timestamp, status from ...

  5. Webfrom 生成流水号 组合查询 Repeater中单选与复选控件的使用 JS实战应用

                                             Default.aspx 网页界面 <%@ Page Language="C#" AutoE ...

  6. github上的QT源码,必要的时候还是应该看一下,仅凭猜测很容易出错

    QCoreApplication::processEvents 他处理的时候拿的是current不是qAppqApp的话,才是和主线程密切相关的 一直觉得QT源码复杂,有点怕,所以没怎么看 我也看不懂 ...

  7. Eclipse选项卡式的属性视图(The Eclipse Tabbed Properties View)

    Eclipse工作台提供了一个性能视图用于查看(和/或编辑)选定项目的属性. 在本文中,您将学习怎样使用选项卡式的属性视图创建一个性能增强的用户界面视图. 1.引言 Eclipse工作台提供了一个属性 ...

  8. android 设置字体颜色、EditText自己主动输入转换成大写字母的多种方式

    在TextView上面设置某一个字的字体颜色为指定颜色时,能够通过java类SpannableString类和Html语言来实现. (一)SpannableString类方式 private void ...

  9. [置顶] Android下实现自动关机的方法总结

    最近在网上看了一些Android下实现自动关机的方法,有的不行,有的只适用一些机型,有的适用于大部分机型,笔者在此总结一下 法一: Intent newIntent = new Intent(Inte ...

  10. MFC获取rgb图像数据后动态显示及保存图片的方法

    该情况可用于视频通信中获取的位图数据回放显示或显示摄像头捕获的本地图像 第一种方法 #include<vfw.h> 加载 vfw32.lib  链接库 //---------------- ...