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. [Redux] React Todo List Example (Toggling a Todo)

    /** * A reducer for a single todo * @param state * @param action * @returns {*} */ const todo = ( st ...

  2. google login page

    </pre><pre name="code" class="html"><div class="container&qu ...

  3. 实现Android 版网页快照功能

    现在一般的购物网站,在你完成交易后都会将页面拍照以免日后发生商务纠纷,而对于我们移动开发者这个传统互联网上的优秀经验也同样给了我们一些设计上的启迪,接下来我将几种实现思路写出来供大家参考. 方案一:使 ...

  4. Chrome: Shockwave Flash isn't responding

    这个问题问 Google 解决得比较快,百度里尽是转载党的东西! 1. 到 chrome://settings/content 找到 Plug-ins 项目 2. 点击 Plug-ins 里的 Exc ...

  5. overcast

    关于一个利用relative的简单布局,firefox上出现一点问题,暂且不明原因 firefox的 chrome的 代码记录 <!DOCTYPE html> <html lang= ...

  6. js获取页面名称

    function pageName() {    var strUrl = location.href;    var arrUrl = strUrl.split("/");    ...

  7. NSURLSessionDataTask

    #import "ViewController.h" @interface ViewController ()<NSURLSessionDelegate,NSURLSessi ...

  8. sql_autoload_register() 函数 和__autoload() 的区别

    1:__autoload($class) 因为是一个函数,所以只能定义一次,使用多个会冲突报错;而 sql_autoload_register('function') 可定义多个,它有效地创建一个队列 ...

  9. jQuery模拟点击A标记

    这个问题弄了半小时没想明白,后来觉得是这样的. 菜单 <li class="menu"><a href="xxx.com" target=&q ...

  10. 使用 c# 调用进程相关开发

    最近在维护公司的以前项目中发现,使用到了进程相关知识.现在将此总结,以备后面查看复习. 一.进程查看器     程序在运行的时候,操作系统就会为其分配一个进程.那么进程到底是什么东西呢? 实际上,进程 ...