poj 3176 Cow Bowling(dp基础)
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基础)的更多相关文章
- 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 1163 The Triangle &poj 3176 Cow Bowling (dp)
id=1163">链接:poj 1163 题意:输入一个n层的三角形.第i层有i个数,求从第1层到第n层的全部路线中.权值之和最大的路线. 规定:第i层的某个数仅仅能连线走到第i+1层 ...
- POJ 3176 Cow Bowling
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13016 Accepted: 8598 Desc ...
- poj 3176 Cow Bowling(区间dp)
题目链接:http://poj.org/problem?id=3176 思路分析:基本的DP题目:将每个节点视为一个状态,记为B[i][j], 状态转移方程为 B[i][j] = A[i][j] + ...
- POJ 3176 Cow Bowling (水题DP)
题意:给定一个金字塔,第 i 行有 i 个数,从最上面走下来,只能相邻的层数,问你最大的和. 析:真是水题,学过DP的都会,就不说了. 代码如下: #include <cstdio> #i ...
- POJ - 3176 Cow Bowling 动态规划
动态规划:多阶段决策问题,每步求解的问题是后面阶段问题求解的子问题,每步决策将依赖于以前步骤的决策结果.(可以用于组合优化问题) 优化原则:一个最优决策序列的任何子序列本身一定是相当于子序列初始和结束 ...
- poj 2955 Brackets (区间dp基础题)
We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a ...
- POJ 3267-The Cow Lexicon(DP)
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8252 Accepted: 3888 D ...
- POJ 3613 [ Cow Relays ] DP,矩阵乘法
解题思路 首先考虑最暴力的做法.对于每一步,我们都可以枚举每一条边,然后更新每两点之间经过\(k\)条边的最短路径.但是这样复杂度无法接受,我们考虑优化. 由于点数较少(其实最多只有\(200\)个点 ...
随机推荐
- (转)命令行下,用 xcodebuild 生成ipa文件,通过 itms-services 协议安装
准备工作:已经设置好,xcode中的证书,证书必须是企业级证书,才能通过 itms-services 协议安装 Step 1: 把以下代码保存到一个web目录中,命名为 “auto.plist”,注 ...
- 【调试技巧】FireFox作为移动端的设置
1.在地址栏输入“about:config”,按下回车进入设置菜单. 2.找到“general.useragent.override”,如果没有这一项,则点右键“新建”->“字符串”,输入这个字 ...
- 【实验 1-1】编写一个简单的 TCP 服务器和 TCP 客户端程序。程序均为控制台程序窗口。
在新建的 C++源文件中编写如下代码. 1.TCP 服务器端#include<winsock2.h> //包含头文件#include<stdio.h>#include<w ...
- ExtJS4.2学习(11)——高级组件之Grid
大纲: 1.首先,搭建起来一个最基础的Grid组件: 2.其次,利用前边MVC架构将代码重构: 3.再者,介绍下Grid的一些特性. 一.搭建基础的Grid组件 在文章的开始,我们首先简单的搭建一个G ...
- tstring
是的,一旦知道 TCHAR 和_T 是如何工作的,那么这个问题很简单.基本思想是 TCHAR 要么是char,要么是 wchar_t,这取决于 _UNICODE 的值: // abridged f ...
- ASP.NET静态页生成方法(模板替换)
本文实例讲述了ASP.NET静态页生成方法的一种简单方法,就是替换内容法. 适用场景 模板比较固定,页面替换内容较少. 基本原理 此方法中静态页生成用到的就是匹配跟替换了,首先得读取模板页的html内 ...
- java开发webservice的几种方式
webservice的应用已经越来越广泛了,下面介绍几种在Java体系中开发webservice的方式,相当于做个记录. 1.Axis2 Axis是apache下一个开源的webservice开发组件 ...
- JavaScripts学习日记——DOM SAX JAXP DEMO4J XPath
今日关键词: XML解析器 DOM SAX JAXP DEMO4J XPath XML解析器 1.解析器概述 什么是解析器 XML是保存数据的文件,XML中保存的数据也需要被程序读取然后使用.那么程序 ...
- VritualBox 中Debian安装tool
VritualBox 中Debian安装tool 环境 Debian 8 VirtualBox 配置Debian的源 #163源 deb http://mirrors.163.com/debian/ ...
- Objective-C 异常处理
#import <UIKit/UIKit.h> #import "AppDelegate.h" int main(int argc, char * argv[]) { ...