HDU -- 2084 数塔(简单DP)
HDU -- 2084 数塔
题意:
自上而下,选择一条累计和最大的路径
分析:
顶点只与左右两个子节点相关,且子节点路径的选择与顶点无关(无后效性)
状态dp[i][j]:表示(i,j)点向下得到的最大累计和
转移方程:
dp[i][j] = max(dp[i+1][j], dp[i+1][j+1]) + v[i][j];
核心:
for(i = n; i>=1; i--) {for(j = 1; j<=i; j++){dp[i][j] = max(dp[i+1][j], dp[i+1][j+1]) + v[i][j];}}
代码:
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <time.h>using namespace std;int v[100+10][100+10];
int dp[100+10][100+10];int main()
{freopen("a.txt", "r", stdin);int t, n, i, j;scanf("%d", &t);while(t--){scanf("%d", &n);for(i = 1; i<=n; i++){for(j = 1; j<=i; j++){scanf("%d", &v[i][j]);}}memset(dp, 0, sizeof(dp));for(i = n; i>=1; i--){for(j = 1; j<=i; j++){dp[i][j] = max(dp[i+1][j], dp[i+1][j+1]) + v[i][j];}}printf("%d\n", dp[1][1]);}return 0;
}
转载于:https://blog.51cto.com/739789987/1437414
HDU -- 2084 数塔(简单DP)相关推荐
- hdu 2084 数塔(DP)
数塔 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...
- HDU 2084 数塔 DP
http://acm.hdu.edu.cn/showproblem.php?pid=2084 题目: 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走 ...
- HDU 2084 数塔(DP)(JAVA版)
数塔 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...
- HDU - 2084 数塔
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084 #include <iostream> #include <string.h& ...
- HDU-2084 数塔 经典dp,水
1.HDU-2084 数塔 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084 3.总结:从下往上推,最后归于顶点.方程为 dp[i][j] ...
- hdu1176 免费馅饼 ( 数塔(DP))
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- 数塔 简单的 动态规划
挺简单的 , 从下向上将 下一行的 数字向上 一行 加 然后 将 这一行的 再向上 + 加到 最上面的时候 最上面的 就是 最大的值 #include<stdio.h> # ...
- HDU2084 数塔【DP】
数塔 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...
- SDJZU_新生_递推动规_HDU 2084 数塔
数塔 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB 64bit IO Fo ...
最新文章
- 安全测试之XSS攻击
- 小米澄清传闻:不存在跨境转移利润及逃避缴纳税款行为
- 移植Linux3.4.2版本内核到mini2440
- 设置 NSZombieEnabled 定位 EXC_BAD_ACCESS 错误
- UI基础控件创建(UILabel、UITextField、UIButton)
- grunt + compass
- C语言中你可能会用到的字符串函数的代码
- 毕马威_毕马威中国为清华大学经管学院学生现场授课
- 财商第2课笔记_复利
- 网络对战五子棋(web-gobang)项目
- Vue + Spring Boot 项目实战(十三):使用 Shiro 实现用户信息加密与登录认证
- codeforces869EThe Untended Antiquity(二维树状数组)
- html snippets怎么配置,用Snippets创建自己喜欢的注释格式
- Python爬虫学习 7 —— 正则表达式
- CSS——网页版心和布局流程
- linux 指定cpu运行线程,关于linux:如何查看运行线程的CPU核心?
- NPL笔记——语言模型
- Expected a string but was BEGIN_OBJECT at line 1 column 2 path $
- 班子不到位,一切都白费
- eygle 期待与拥抱变化 - 谈谈技术人的技术路
热门文章
- 关于程序猿的学习方法的一些总结
- Linq学习from let where子句
- python多重继承
- MySQL外键约束On Delete、On Update各取值的含义
- 【跃迁之路】【728天】程序员高效学习方法论探索系列(实验阶段485-2019.2.18)...
- 信息系统开发平台OpenExpressApp:【OpenTest】 之 如何实现自动化测试框架
- Apache发布Groovy 2.5正式版及3.0预览版
- 4.Windows下安装ZooKeeper
- Tor 出口节点将运行在图书馆的电脑上
- 《TensorFlow技术解析与实战》——导读