POJ3176:Cow Bowling(数字三角形问题)
地址:http://poj.org/problem?id=3176
题目解析:没什么好说的,之前上课时老师讲过。从下往上找,每一个三角形的顶点可由两个角加上顶点的值 两种方式得到 ,用dp数组保存下最大值即可。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <math.h>
#define N 400
#define inf 0x3f3f3f3f
typedef int ll;
using namespace std;
int a[N][N],dp[N][N];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=; i<=n; i++)
{
for(int j=; j<=i; j++)
scanf("%d",&a[i][j]);
}
for(int i=; i<=n; i++)
{
dp[n][i]=a[n][i];
}
for(int i=n-; i>=; i--)
{
for(int j=; j<=i; j++)
{
dp[i][j]=max(a[i][j]+dp[i+][j],a[i][j]+dp[i+][j+]);
}
}
printf("%d\n",dp[][]);
}
return ;
}
POJ3176:Cow Bowling(数字三角形问题)的更多相关文章
- POJ3176——Cow Bowling(动态规划)
Cow Bowling DescriptionThe cows don't use actual bowling balls when they go bowling. They each take ...
- POJ3176 Cow Bowling 2017-06-29 14:33 23人阅读 评论(0) 收藏
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19173 Accepted: 12734 Des ...
- Poj3176 Cow Bowling (动态规划 数字三角形)
Description The cows don't use actual bowling balls when they go bowling. They each take a number (i ...
- poj-3176 Cow Bowling &&poj-1163 The Triangle && hihocoder #1037 : 数字三角形 (基础dp)
经典的数塔模型. 动态转移方程: dp[i][j]=max(dp[i+1][j],dp[i+1][j+1])+p[i][j]; #include <iostream> #include ...
- POJ_3176_Cow_Bowling_(数字三角形)_(动态规划)
描述 http://poj.org/problem?id=3176 给出一个三角形,每个点可以走到它下面两个点,将所有经过的点的值加起来,问最大的和是多少. Cow Bowling Time Limi ...
- POJ 3176 Cow Bowling(dp)
POJ 3176 Cow Bowling 题目简化即为从一个三角形数列的顶端沿对角线走到底端,所取得的和最大值 7 * 3 8 * 8 1 0 * 2 7 4 4 * 4 5 2 6 5 该走法即为最 ...
- G:数字三角形
总时间限制: 1000ms 内存限制: 65536kB描述73 88 1 02 7 4 44 5 2 6 5 (图1) 图1给出了一个数字三角形.从三角形的顶部 ...
- POJ 3176 Cow Bowling
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13016 Accepted: 8598 Desc ...
- 4829 [DP]数字三角形升级版
4829 [DP]数字三角形升级版 时间限制: 1 s 空间限制: 16000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 从数字三角形的顶部(如图, ...
随机推荐
- 终极方法,pjsip发起多方对讲出错Too many objects of the specified type (PJ_ETOOMANY)
http://blog.csdn.net/zhangjm_123/article/details/26727221 —————————————————————————————————————————— ...
- easyui datagrid 列拖动
实现代码-code <script type="text/javascript"> $.extend($.fn.datagrid.methods, { columnMo ...
- Statement和PreparedStatement都是用来发送和执行SQL语句的
Statement和PreparedStatement都是用来发送和执行SQL语句的 DriverManager管理一组驱动程序
- JAVA中所有与集合有关的实现类都是这六个接口的实现类
JAVA中所有与集合有关的实现类都是这六个接口的实现类. Collection接口:集合中每一个元素为一个对象,这个接口将这些对象组织在一起,形成一维结构. List接口代表按照元素一定的相关顺序来组 ...
- tinycore remaster方法
11.1. PrerequisitesYou need a Linux distribution with the required programs available:cpio, tar, gzi ...
- request Dispatch
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletExcepti ...
- unity发射弓箭轨迹的实现
无论是愤怒的小鸟,还是弓箭发射功能,亦或者模拟炮弹受重力影响等抛物线轨迹,都可以使用本文的方法,模拟绝对真实. 和往常一样,先说原理.就是抛物运动,在垂直方向上做加速度运动,在水平方向上,做匀速运动. ...
- Margin外边距叠加
外边距(Margin)叠加 只有普通文档流中块级元素(块框)的垂直外边距才会发生外边距叠加.行内框.浮动框和绝对定位框之间的外边距不会叠加 两个相邻兄弟块框 父元素与子元素,并 父元素没有内边距或边框 ...
- cocos2d-x 3.0 使用.plist图片集方法
这个贴.仅仅是为了和我一样的新手,更快的索引. 我使用的是SpritePacker 软件来制作 .plist SpriteFrameCache *frameCache = SpriteFrameCac ...
- Spring_day03--Spring配置c3p0连接池和dao使用jdbcTemplate
Spring配置c3p0连接池和dao使用jdbcTemplate 1 spring配置c3p0连接池 第一步 导入jar包 第二步 创建spring配置文件,配置连接池 原始方式 (1)把代码在配置 ...