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组数据表示挤奶的时间与奶量求最 ...
随机推荐
- 超级炫酷的终端神器 eDEX-UI
目录 eDEX-UI主要亮点: 优点: 软件简介 安装 Linux Windows 效果 更换皮肤 matrix Tron-disrupted 退出 常见问题解答 eDEX-UI,不仅是一款全屏幕.跨 ...
- Figma数值输入框支持拖拽调整功能实现
最近再研究Figma的一些功能设计, 对其中的数值输入框可以直接鼠标拖拽的这个设计印象非常深刻. 这里用了其他网友的一张动态截图演示一下效果. 实际这个拖拽的功能不止看到的这么简单, 在深度研究使用之 ...
- Standard Template Libary or C++ Standard Library
C++提供一套标准的library称为C++ standard library完全以template完成,所以又被称为Standard Template Library.这套library专门有于实现 ...
- ComfyUI进阶:Comfyroll插件 (六)
ComfyUI进阶:Comfyroll插件 (六) 前言: 学习ComfyUI是一场持久战,而Comfyroll 是一款功能强大的自定义节点集合,专为 ComfyUI 用户打造,旨在提供更加丰富和专业 ...
- 题解:CF1971D Binary Cut
题解:CF1971D Binary Cut 题意 给予你一个 \(01\) 字符串,你可以将它分割,分割后必须排成先 \(0\) 后 \(1\) 的格式. 求最少分割为几部分. 思路 将 \(0\) ...
- 【转载】SCI审稿过程中的几种状态
原文地址: http://cjsphd.blog.163.com/blog/static/44718111201191175154300/ 审稿中涉及到的人: EIC-Editor in Chief ...
- 国产AI训练卡,对标美国NVIDIA公司的A100,华为昇腾Atlas 300T A2(Ascend 910B4)高性能GPU/NPU/AI推理/国产计算/信创训练卡 —— 电商平台已开售
China has successfully achieved the localization of AI chips, breaking through the technological res ...
- pytorch 第三方模块 GraphNAS 安装成功记录
实验室的小师妹要安装pytorch的第三方模块,经过多方努力没有安装上,后来我接手后也是感觉头疼. 该模块地址: https://github.com/GraphNAS/GraphNAS 该模块主 ...
- Linux环境下配置vscode的C/C++ 的make编译环境(编写makefile方式)
主要前提内容参照前文: Linux环境下配置vscode的C/C++编译环境 =========================================================== 代 ...
- Linux磁盘/硬盘测速,dd命令
参考: https://blog.csdn.net/Franciz777/article/details/126779259 ===================================== ...