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 ( <= N <= ) rows, determine the highest possible sum achievable.

Input

Line : A single integer, N 

Lines ..N+: Line i+ contains i space-separated integers that represent row i of the triangle.

Output

Line : 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.

Source

 
 
 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 356
int mp[N][N];
int dp[N][N];
int main()
{
int n;
while(scanf("%d",&n)==){
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++){
for(int j=;j<=i;j++){
scanf("%d",&mp[i][j]);
}
}
dp[][]=mp[][];
for(int i=;i<=n;i++){
for(int j=;j<=i;j++){
dp[i][j]=max(dp[i-][j-]+mp[i][j],dp[i-][j]+mp[i][j]);
}
}
int maxn=-;
for(int i=;i<=n;i++){
maxn=max(maxn,dp[n][i]);
}
printf("%d\n",maxn);
}
return ;
}

poj 3176 Cow Bowling(dp基础)的更多相关文章

  1. POJ 3176 Cow Bowling(dp)

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

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

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

  3. POJ 3176 Cow Bowling

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

  4. poj 3176 Cow Bowling(区间dp)

    题目链接:http://poj.org/problem?id=3176 思路分析:基本的DP题目:将每个节点视为一个状态,记为B[i][j], 状态转移方程为 B[i][j] = A[i][j] + ...

  5. POJ 3176 Cow Bowling (水题DP)

    题意:给定一个金字塔,第 i 行有 i 个数,从最上面走下来,只能相邻的层数,问你最大的和. 析:真是水题,学过DP的都会,就不说了. 代码如下: #include <cstdio> #i ...

  6. POJ - 3176 Cow Bowling 动态规划

    动态规划:多阶段决策问题,每步求解的问题是后面阶段问题求解的子问题,每步决策将依赖于以前步骤的决策结果.(可以用于组合优化问题) 优化原则:一个最优决策序列的任何子序列本身一定是相当于子序列初始和结束 ...

  7. poj 2955 Brackets (区间dp基础题)

    We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a ...

  8. POJ 3267-The Cow Lexicon(DP)

    The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8252   Accepted: 3888 D ...

  9. POJ 3613 [ Cow Relays ] DP,矩阵乘法

    解题思路 首先考虑最暴力的做法.对于每一步,我们都可以枚举每一条边,然后更新每两点之间经过\(k\)条边的最短路径.但是这样复杂度无法接受,我们考虑优化. 由于点数较少(其实最多只有\(200\)个点 ...

随机推荐

  1. LaTeX笔记

    1.上下标: $x^n$, $x^{123}$, $x_n$, $x_{123}$, $C_n^m$, $C_{100}^{50}$ $x^n$, $x^{123}$, $x_n$, $x_{123} ...

  2. Lenovo k860i 移植Android 4.4 cm11进度记录【下篇--实时更新中】

    2014.8.24 k860i的cm11的移植在中断了近两三个月之后又開始继续了,进度记录的日志上一篇已经没什么写的了,就完结掉它吧,又一次开一篇日志做下篇好了.近期的战况是,在scue同学的努力之下 ...

  3. gcc和g++编译c或者c++文件碰到的问题

    gcc和g++都是GNU(组织)的一个编译器.        误区一:gcc只能编译c代码,g++只能编译c++代码      两者都可以,但是请注意:      1.后缀为.c的,gcc把它当作是C ...

  4. asp.net读取Excel中的数据问题

      1.Microsoft.ACE.OLEDB.12.0 与Microsoft.Jet.OLEDB.4.0 在通过ADO对Excel对象进行连接时(此时Excel则认为是一个数据源),需要配置对Exc ...

  5. sql中视图视图的作用

    视图是一个虚拟表,其内容由查询定义.同真实的表一样,视图包含一系列带有名称的列和行数据.但是,视图并不在数据库中以存储的数据值集形式存在.行和列数据来自由定义视图的查询所引用的表,并且在引用视图时动态 ...

  6. handler机制和异步更新UI页面

    Android 提供了Handler和Looper来满足线程之间的通行,Handler是先进先出原则,Looper类用来管理特定线程内对象之间的消息互换,也可以使用Runnable来完成页面异步更新 ...

  7. ORACLE基本SQL语句-用户及建表篇

    一.用户相关SQL语句 /*新建用户*/create user ; 说明:SA用户名,2013密码 /*授权connect,resource给用户sa*/grant connect,resource ...

  8. Swift中的协议

    协议: 1.Swift协议用于定义多个类型应该遵守的规范 2.协议定义了一种规范, 不提供任何实现 3.协议统一了属性名, 方法, 下标, 但是协议并不提供任何实现 4.语法格式: [修饰符] pro ...

  9. Swift中类的两段式构造(类的构造过程)

    import Foundation /* 类的构造需要两个阶段: 第一阶段: 1.程序调用子类的某个构造器 2.为实例分配内存, 此时实例的内存还没有被初始化 3.指定构造器确保子类定义的所有实例存储 ...

  10. C#读取word模版并对指定域写入数据保存为新word

    引用: using System;using System.Collections.Generic;using System.Aspose.Words;using System.Windows.For ...