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. IDEA 自动化配置

    # IDEA maven web项目:http://www.cnblogs.com/Sinte-Beuve/p/5730553.html # IDEA 数据库自动化 ## 功能 ① SQL 代码自动感 ...

  2. Linux学习之“fork函数”

    n返回值: fork函数调用一次,但是返回两次:在子进程中返回0,在父进程中返回子进程ID,出错返回-1.通过返回值,可以确定是在父进程还是子进程中. n子进程和父进程继续执行fork调用之后的指令. ...

  3. 在UWP的XAML中使用原始类型

    问题: I'm trying to access the system namespace for StaticResource variables in XAML on UWP. Here's (m ...

  4. 变量的选择——Lasso&Ridge&ElasticNet

    对模型参数进行限制或者规范化能将一些参数朝着0收缩(shrink).使用收缩的方法的效果提升是相当好的,岭回归(ridge regression,后续以ridge代称),lasso和弹性网络(elas ...

  5. Linux基础命令杂记

    今天又一次搞Linux生产环境搭建.这是种步骤很多,很繁琐而且又不得不做的事情.虽然做过很多次,但还是有很多步骤.命令不记得,每一次到处找资料很麻烦,于是将一些步骤记下,以便查找. 登录远程MySQL ...

  6. .NET中扩展方法和Enumerable(System.Linq)

    LINQ是我最喜欢的功能之一,程序中到处是data.Where(x=x>5).Select(x)等等的代码,她使代码看起来更好,更容易编写,使用起来也超级方便,foreach使循环更加容易,而不 ...

  7. spring源码解析之IOC容器(三)——依赖注入

    上一篇主要是跟踪了IOC容器对bean标签进行解析之后存入Map中的过程,这些bean只是以BeanDefinition为载体单纯的存储起来了,并没有转换成一个个的对象,今天继续进行跟踪,看一看IOC ...

  8. spring常见十大异常

    一.找不到配置文件的异常 [plain] view plaincopy org.springframework.beans.factory.BeanDefinitionStoreException:  ...

  9. SpringBoot从入门到精通一(idea优雅搭建SpringBoot项目)

    前言 在没有SpringBoot之前,我们搭建的是SSM(SpingMVC+Spring+Mybatis)项目,在搭建SSM项目的时候,我们要经过一系列的繁琐配置,例如:application,web ...

  10. 【入门】WebRTC知识点概览 | 内有技术干货免费下载

    什么是WebRTC WebRTC 即Web Real-Time Communication(网页实时通信)的缩写,是一个支持网页浏览器之间进行实时数据传输(包括音频.视频.数据流)的技术.经过多年的发 ...