POJ-3176 Cow Bowling(基础dp)
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:
7 3 8 8 1 0 2 7 4 4 4 5 2 6 5
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 (1 <= N <= 350) rows, determine the highest possible sum achievable.
Input Line 1: A single integer, N Lines 2..N+1: Line i+1 contains i space-separated integers that represent row i of the triangle.
Output Line 1: The largest sum achievable using the traversal rules
Sample Input 5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
Sample Output 30
刚差不多刚看完动态规划,把小白书的例题大半都看懂了,也查了不少博客,然而做起题目来,连状态都不太会定义。
于是乎又查了起来,嗯看到了别人对状态的定义:way[i][j]表示以第i行j列的位置作为终点的路线的最大权值。 (注意区分初始化时的意义)
好的开始自己写状态转移方程:dp[i][j] = a[i][j] + max( dp[i+1][j], dp[i+1][j+1])
后来发现别人的更加简单:num[i][j] += max(num[i+1][j], num[i+1][j+1])
由于递推是沿着三角形向上的,就直接在原来的值上更新,只是得注意区分初始化时的意义
附上AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int num[355][355];
int main()
{
int n;
cin>>n;
for (int i = 1; i <=n; i++)
for (int j = 1; j <=i; j++)
cin>>num[i][j];
for (int i = n; i >= 1; i--)
for (int j = 1; j <= i; j++)
num[i][j] += max(num[i+1][j], num[i+1][j+1]);
cout<<num[1][1]<<endl; return 0;
}
POJ-3176 Cow Bowling(基础dp)的更多相关文章
- 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)
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)
题意:给定一个金字塔,第 i 行有 i 个数,从最上面走下来,只能相邻的层数,问你最大的和. 析:真是水题,学过DP的都会,就不说了. 代码如下: #include <cstdio> #i ...
- POJ - 3176 Cow Bowling 动态规划
动态规划:多阶段决策问题,每步求解的问题是后面阶段问题求解的子问题,每步决策将依赖于以前步骤的决策结果.(可以用于组合优化问题) 优化原则:一个最优决策序列的任何子序列本身一定是相当于子序列初始和结束 ...
- 【POJ 3176】Cow Bowling(DP)
题 Description The cows don't use actual bowling balls when they go bowling. They each take a number ...
- poj 2184 Cow Exhibition(dp之01背包变形)
Description "Fat and docile, big and dumb, they look so stupid, they aren't much fun..." - ...
- poj 3616 Milking Time (基础dp)
题目链接 http://poj.org/problem?id=3616 题意:在一个农场里,在长度为N个时间可以挤奶,但只能挤M次,且每挤一次就要休息t分钟: 接下来给m组数据表示挤奶的时间与奶量求最 ...
随机推荐
- Android SDK Build-tools的版本已经高于Android SDK Platform-tools版本 的解决办法
解决Unknown error: Unable to build: the file dx.jar was not loaded from the SDK folder!最近渐渐迁移到Android ...
- pytest + 登录禅道 :自动提交bug-编辑bug-确认bug-解决bug-关闭bug
pytest + 登录禅道 :自动提交bug-编辑bug-确认bug-解决bug-关闭bug 一.Pycharm中创建项目结构 1.新建一个工程,工程名称自己定义,如:zentao 2.在工程的根目 ...
- 【Java】轻量Excel读写框架JXL学习
参考黑马教程: https://www.bilibili.com/video/BV1eA41157va?p=5 写着写着发现有更好的Demo案例: https://cloud.tencent.com/ ...
- 【Windows】开放共享目录
在项目里面做数据迁移时发现,WindowsServer的多个主机可以进行磁盘共享访问 但是自己设置是灰白无法点击的 文件目录共享还是可以进行设置的 1.找到自己需要共享的目录,右键选择[属性],并找到 ...
- 【转载】ubuntu用户/linux用户登录后没有自动加载.bashrc
版权声明:本文为CSDN博主「安安爸Chris」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明. 原文链接:https://blog.csdn.net/mimiduc ...
- 【转载】解决Nvidia-smi没有进程但是显存不释放的问题
----------------版权声明:本文为CSDN博主「打拳的土豆」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明.原文链接:https://blog.csdn ...
- 【客户案例】白鲸开源WhaleStudio助力某证券公司打造全面数据解决方案:探析DataOps平台革新与应用
背景 近年来随着国际形势的变化,信创产业成为我国国家战略的一部分.一直以来,一直以来,全球 ICT 产业底层标准.架构.产品.生态等要素均由国外公司或机构制定和控制,使我国 ICT 产业乃至广大用户面 ...
- vue开发者工具dev-tool的安装
1.下载网址:https://github.com/Redxym/dev-tools 2.谷歌浏览器->扩展程序,拖动刚刚下载好的压缩包,将chrome文件夹添加至'加载已解压的扩展程序' // ...
- blender-点线面操作
- [KEYENCE Programming Contest 2023 Autumn(AtCoder Beginner Contest 325) E
KEYENCE Programming Contest 2023 Autumn(AtCoder Beginner Contest 325) - AtCoder E E - Our clients, p ...