POJ 3176 Cow Bowling(dp)
题目简化即为从一个三角形数列的顶端沿对角线走到底端,所取得的和最大值
7
*
3 8
*
8 1 0
*
2 7 4 4
*
4 5 2 6 5 该走法即为最大值 分析:简单的动态规划,从上往下一层一层的考虑,对于每一行的最左边和最右边只有一种走法,只需要简单的相加,
对于中间的数要考虑是加上左上角的数还是加右上角的数,加上两者中的较大者 代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAX_N = ;
int dp[MAX_N+][MAX_N+];
int n;
int main() {
scanf("%d", &n);
memset(dp, , sizeof(dp)); for(int i = ; i <= n; i++) {
for(int j = ; j < i; j++) {
scanf("%d", &dp[i][j]);
if(j == ) dp[i][j] += dp[i-][j];
else if(j == i - ) dp[i][j] += dp[i-][j-];
else dp[i][j] += max(dp[i-][j],dp[i-][j-]);
}
}
int ans = ;
for(int i = ; i < n; i++) ans = max(dp[n][i], ans);
printf("%d\n", ans);
return ;
}
POJ 3176 Cow Bowling(dp)的更多相关文章
- 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基础)
Description The cows don't use actual bowling balls when they go bowling. They each take a number (i ...
- 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 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\)个点 ...
- POJ 3176:Cow Bowling
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13464 Accepted: 8897 Desc ...
随机推荐
- CodeForces 471D MUH and Cube Walls -KMP
Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of ...
- 2018 Machine Learning
2018/8/13 线性模型(西瓜书P53~P73) Optimizer https://blog.csdn.net/u012151283/article/details/78154917 2018/ ...
- HDU 6128 Inverse of sum(同余)
http://acm.hdu.edu.cn/showproblem.php?pid=6128 题意:有一个a数列,并且每个数都小于p,现在要求有多少对$(i,j)$满足$\frac{1}{a_i+a_ ...
- Could not find a package configuration file provided by 'ecl_threads' ,.................couldn't find required component 'ecl_threads'
sudo apt-get install ros-kinetic-ecl-threads
- 测试报告 之 testNG + Velocity 编写自定义html测试报告
之前用testNG自带的test-outputemailable-report.html,做出的UI自动化测试报告,页面不太好看. 在网上找到一个新的报告编写,自己尝试了一下,埋了一些坑,修改了输出时 ...
- Jmeter高阶学习,运用NotePad++编写工程,随意复制多个工程到同一个工程
Jmeter创建了工程之后,保存文件后就是一个jmx后缀的文件,你有没有试过单独用文本编辑器打开文件,编辑文件? Step1: 最简单的Jmeter工程,只有一个测试计划 <?xml versi ...
- highcharts PHP中使用
官网 https://www.hcharts.cn/demo/highcharts html <div id="container" style="min-widt ...
- 【转】libxml2 如何获得某个节点的所有信息
网址:http://bbs.csdn.net/topics/380115580 顶楼: 我的需求是这样的,我使用libxml2从内存中解析一个xml文件,需要修改某个节点下的一个子节点,修改完成之后, ...
- [STL][C++]LIST
参考:http://blog.csdn.net/whz_zb/article/details/6831817 list是双向循环链表,,每一个元素都知道前面一个元素和后面一个元素.在STL中,list ...
- [ios]iOS8 定位
参考:http://www.2cto.com/kf/201410/342392.html http://blog.csdn.net/yongyinmg/article/details/39521523 ...