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)相关推荐

  1. hdu 2084 数塔(DP)

    数塔 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  2. HDU 2084 数塔 DP

    http://acm.hdu.edu.cn/showproblem.php?pid=2084 题目: 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走 ...

  3. HDU 2084 数塔(DP)(JAVA版)

    数塔 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  4. HDU - 2084 数塔

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084 #include <iostream> #include <string.h& ...

  5. HDU-2084 数塔 经典dp,水

    1.HDU-2084   数塔 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084 3.总结:从下往上推,最后归于顶点.方程为  dp[i][j] ...

  6. hdu1176 免费馅饼 ( 数塔(DP))

    免费馅饼 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  7. 数塔 简单的 动态规划

    挺简单的 , 从下向上将 下一行的 数字向上 一行 加     然后  将 这一行的  再向上 +   加到 最上面的时候 最上面的 就是 最大的值 #include<stdio.h> # ...

  8. HDU2084 数塔【DP】

    数塔 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  9. SDJZU_新生_递推动规_HDU 2084 数塔

    数塔 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Fo ...

最新文章

  1. 安全测试之XSS攻击
  2. 小米澄清传闻:不存在跨境转移利润及逃避缴纳税款行为
  3. 移植Linux3.4.2版本内核到mini2440
  4. 设置 NSZombieEnabled 定位 EXC_BAD_ACCESS 错误
  5. UI基础控件创建(UILabel、UITextField、UIButton)
  6. grunt + compass
  7. C语言中你可能会用到的字符串函数的代码
  8. 毕马威_毕马威中国为清华大学经管学院学生现场授课
  9. 财商第2课笔记_复利
  10. 网络对战五子棋(web-gobang)项目
  11. Vue + Spring Boot 项目实战(十三):使用 Shiro 实现用户信息加密与登录认证
  12. codeforces869EThe Untended Antiquity(二维树状数组)
  13. html snippets怎么配置,用Snippets创建自己喜欢的注释格式
  14. Python爬虫学习 7 —— 正则表达式
  15. CSS——网页版心和布局流程
  16. linux 指定cpu运行线程,关于linux:如何查看运行线程的CPU核心?
  17. NPL笔记——语言模型
  18. Expected a string but was BEGIN_OBJECT at line 1 column 2 path $
  19. 班子不到位,一切都白费
  20. eygle 期待与拥抱变化 - 谈谈技术人的技术路

热门文章

  1. 关于程序猿的学习方法的一些总结
  2. Linq学习from let where子句
  3. python多重继承
  4. MySQL外键约束On Delete、On Update各取值的含义
  5. 【跃迁之路】【728天】程序员高效学习方法论探索系列(实验阶段485-2019.2.18)...
  6. 信息系统开发平台OpenExpressApp:【OpenTest】 之 如何实现自动化测试框架
  7. Apache发布Groovy 2.5正式版及3.0预览版
  8. 4.Windows下安装ZooKeeper
  9. Tor 出口节点将运行在图书馆的电脑上
  10. 《TensorFlow技术解析与实战》——导读