HDU 2084:https://vjudge.net/problem/HDU-2084

Problem Describe :

When it comes to the DP algorithm, a classic example is the tower problem, which is described as:There are towers as shown below, which require walking from the top to the bottom. If each step can only go to an adjacent node, what is the maximum number of nodes passing through?

Keyworld in problem is  "maximun",so we can consider DP. After we think the problem,we can divide this problem into many subproblem,,The problem has the best substructure properties.If the solution to the subproblem contained in the optimal solution of the problem is also optimal, we call the problem the optimal substructure property.

Firstly,we can analyze the question and write the table which reflects the optimum solution of every elements.we use i and j to represent rows and columns.it has N rows and N columns,so we can draw N*N table.in this question ,5*5 is ok.

when i = N,then the optimum solution is element itself.

4 5 2 6 5

i = N-1,the optimum solution is max(i,j) = MAX{max(i+1,j),max(i+1,j+1)}+elem[i][j].

7 12 10 10  

i = N-2 .. ... 1,follow above.

so the complete table is:

30        
23 21      
20 13 10    
7 12  10 10  
5 2 6 5

So the  sate equation is:

AC Code :

 #include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
const int N = ;
int Elem[N][N];
int DP[N][N];
int main()
{
int n,T;
cin>>T;
while(T--)
{
cin>>n;
for(int i = ;i <= n;++i)
for(int j = ;j <= i;j++)
cin>>Elem[i][j];
for(int i = ;i <= n;i++)
DP[n][i] = Elem[n][i];
for(int i = n-;i >= ;--i)
for(int j = ;j <= i;++j)
DP[i][j] = max(DP[i+][j],DP[i+][j+])+Elem[i][j];
cout<<DP[][]<<endl;
}
return ;
}

Siimple DP (Dynamic Programing)的更多相关文章

  1. 动态规划——DP算法(Dynamic Programing)

    一.斐波那契数列(递归VS动态规划) 1.斐波那契数列——递归实现(python语言)——自顶向下 递归调用是非常耗费内存的,程序虽然简洁可是算法复杂度为O(2^n),当n很大时,程序运行很慢,甚至内 ...

  2. #C++初学记录(动态规划(dynamic programming)例题1 钞票)

    浅入动态规划 dynamic programming is a method for solving a complex problem by breaking it down into a coll ...

  3. 详解动态规划(Dynamic Programming)& 背包问题

    详解动态规划(Dynamic Programming)& 背包问题 引入 有序号为1~n这n项工作,每项工作在Si时间开始,在Ti时间结束.对于每项工作都可以选择参加与否.如果选择了参与,那么 ...

  4. 笔试算法题(44):简介 - 动态规划(Dynamic Programming)

    议题:动态规划(Dynamic Programming) 分析: DP主要用于解决包含重叠子问题(Overlapping Subproblems)的最优化问题,其基本策略是将原问题分解为相似的子问题, ...

  5. Java事务处理全解析(六)—— 使用动态代理(Dynamic Proxy)完成事务

    在本系列的上一篇文章中,我们讲到了使用Template模式进行事务管理,这固然是一种很好的方法,但是不那么完美的地方在于我们依然需要在service层中编写和事务处理相关的代码,即我们需要在servi ...

  6. mapping 详解5(dynamic mapping)

    概述 在使用 ES 的时,我们不需要事先定义好映射设置就可以直接向索引中导入文档.ES 可以自动实现每个字段的类型检测,并进行 mapping 设置,这个过程就叫动态映射(dynamic mappin ...

  7. hdu 3709 数字dp(小思)

    http://acm.hdu.edu.cn/showproblem.php?pid=3709 Problem Description A balanced number is a non-negati ...

  8. 【学习笔记】动态规划—斜率优化DP(超详细)

    [学习笔记]动态规划-斜率优化DP(超详细) [前言] 第一次写这么长的文章. 写完后感觉对斜优的理解又加深了一些. 斜优通常与决策单调性同时出现.可以说决策单调性是斜率优化的前提. 斜率优化 \(D ...

  9. Flink原理(七)——动态表(Dynamic tables)

    前言 本文是结合Flink官网,个人理解所得,若是有误欢迎留言指出,谢谢!文中图皆来自官网(链接[1]). 本文将随着下面这个问题展开,针对该问题更为生动的解释可以参见金竹老师的分享(链接[2]). ...

随机推荐

  1. WPF 自定义验证规则

    <Window x:Class="DataBindingExam.MainWindow"        xmlns="http://schemas.microsof ...

  2. Delphi多线程下的ADO编程

    前言: 几个月前接到一个任务:将一后台程序访问数据库的方式从BDE改为ADO,原因是由于业务量的增加,通过BDE不论是向数据库写入数据还是从数据库中读出数据的速度都变得无法忍受,大家都知道ADO在数据 ...

  3. 数据绑定(五)使用集合对象作为列表控件的ItemsSource

    原文:数据绑定(五)使用集合对象作为列表控件的ItemsSource ItemsSource属性可以接收一个IEnumerable接口派生类的实例作为自己的值,ItemsSource里存放的是一条一条 ...

  4. JavaScript严格模式分析

    简要:严格模式(strict mode)是JavaScript在ES5里面新增的编码模式,只要一行代码 就可开启,可谓 非常简单了,而它对于 我们的编码来说到底有什么不同呢? 一. 严格模式的目的? ...

  5. 让bootstrap表格自动出现水平滚动条

    <div class="table-responsive"><!--表格自动出现水平滚动条-> <table id="tb_departme ...

  6. c# 文本超长截断

    根据控件大小进行截断 private void SetStringTruncat(Static.LabelEx lbl) { string oldStr = lbl.Text; if (string. ...

  7. Dependency Injection 筆記 (3)

    续上集.接着要来进一步了解的是 DI 的实现技术,也就是注入相依对象的方式.这里介绍的依赖注入方式,又称为「穷人的 DI」(poor man’s DI),因为这些用法都与特定 DI 工具无关,亦即不使 ...

  8. Java Socket基础[备忘]

    1.服务端----Server.java import javax.swing.*; import java.io.*; import java.net.*; import java.awt.*; i ...

  9. QT创建窗口程序、消息循环和WinMain函数(为主线程建立了一个QEventLoop,并执行exec函数)

    使用QT也有一段时间了,有的时候需要跟踪代码到QT的源码中去查找问题.在这里我将记录一下我跟踪QT源码学习到的一些知识. 我的开发环境是VC6.0+QT4.3.3.QT已经不为VC6.0提供addin ...

  10. APP导航设计九法

    近期在设计APP原型,用EXCEL,用Axure.但无论工具如何,产品本身的界面布局和交互设计确实逃不掉的!网络中有关于APP导航设计的总结: 第一种:app标签导航  易用性:★★★★★   趣味性 ...