Siimple DP (Dynamic Programing)
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 | |
| 4 | 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)的更多相关文章
- 动态规划——DP算法(Dynamic Programing)
一.斐波那契数列(递归VS动态规划) 1.斐波那契数列——递归实现(python语言)——自顶向下 递归调用是非常耗费内存的,程序虽然简洁可是算法复杂度为O(2^n),当n很大时,程序运行很慢,甚至内 ...
- #C++初学记录(动态规划(dynamic programming)例题1 钞票)
浅入动态规划 dynamic programming is a method for solving a complex problem by breaking it down into a coll ...
- 详解动态规划(Dynamic Programming)& 背包问题
详解动态规划(Dynamic Programming)& 背包问题 引入 有序号为1~n这n项工作,每项工作在Si时间开始,在Ti时间结束.对于每项工作都可以选择参加与否.如果选择了参与,那么 ...
- 笔试算法题(44):简介 - 动态规划(Dynamic Programming)
议题:动态规划(Dynamic Programming) 分析: DP主要用于解决包含重叠子问题(Overlapping Subproblems)的最优化问题,其基本策略是将原问题分解为相似的子问题, ...
- Java事务处理全解析(六)—— 使用动态代理(Dynamic Proxy)完成事务
在本系列的上一篇文章中,我们讲到了使用Template模式进行事务管理,这固然是一种很好的方法,但是不那么完美的地方在于我们依然需要在service层中编写和事务处理相关的代码,即我们需要在servi ...
- mapping 详解5(dynamic mapping)
概述 在使用 ES 的时,我们不需要事先定义好映射设置就可以直接向索引中导入文档.ES 可以自动实现每个字段的类型检测,并进行 mapping 设置,这个过程就叫动态映射(dynamic mappin ...
- hdu 3709 数字dp(小思)
http://acm.hdu.edu.cn/showproblem.php?pid=3709 Problem Description A balanced number is a non-negati ...
- 【学习笔记】动态规划—斜率优化DP(超详细)
[学习笔记]动态规划-斜率优化DP(超详细) [前言] 第一次写这么长的文章. 写完后感觉对斜优的理解又加深了一些. 斜优通常与决策单调性同时出现.可以说决策单调性是斜率优化的前提. 斜率优化 \(D ...
- Flink原理(七)——动态表(Dynamic tables)
前言 本文是结合Flink官网,个人理解所得,若是有误欢迎留言指出,谢谢!文中图皆来自官网(链接[1]). 本文将随着下面这个问题展开,针对该问题更为生动的解释可以参见金竹老师的分享(链接[2]). ...
随机推荐
- Delphi 接口使用中,对象生命周期管理,如何释放需要注意的问题
网上有篇文章<Delphi接口编程的两大陷阱>,里面提到接口的生存期管理的问题.但该文章里面提到的两个问题,其实都是对 Delphi 不理解导致的. 先说该篇文章中提到的第一个问题为什 ...
- jQuery省市联动
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...
- rdlc水晶报表在wpf里的使用
1引用程序集 Microsoft.ReportViewer.WinForms 2 xaml 命名空间 xmlns:rv="clr-namespace:Microsoft.Reporting. ...
- miniui处理多重子表级联,一次性提交多表数据的ui要点
在一个ui界面上 有a,b,c三个表 a表只有一条记录,b表有多条记录,c表有多条记录 b是a的子表,c是b的子表 都是一对多关系 一次性下载相关联的c表记录 然后mini-datagrid采用cli ...
- WPF svg 转 xmal
原文:WPF svg 转 xmal 今天wpf里面要用矢量图,美工出的是svg格式的,需要将svg格式的转换为xaml 1.第一个尝试是安装Inkscape,这个软件可以直接将svg另存为xaml,但 ...
- Windows10 【系统周期表】【系统下载表】【大型软件表】
系统周期表 商用名称 商用英文名 代号 版本 系统版本 上市日期 服务周期 备注 Windows 10 无 Threshold 1 1507 10.0.10240.17443 2015.07.29 2 ...
- .gitignore 配置后无效
利用.gitignore过滤文件,如编译过程中的中间文件,等等,这些文件不需要被追踪管理. 现象: 在.gitignore添加file1文件,以过滤该文件,但是通过Git status查看仍显示fil ...
- 漫步Facebook开源C++库Folly之string类设计(散列、字符串、向量、内存分配、位处理等,小部分是对现有标准库和Boost库功能上的补充,大部分都是基于性能的需求而“重新制造轮子”)
就在近日,Facebook宣布开源了内部使用的C++底层库,总称folly,包括散列.字符串.向量.内存分配.位处理等,以满足大规模高性能的需求. 这里是folly的github地址:https:// ...
- 制作Qt应用程序的插件(使用QtPlugin),对比DLL它是全平台通用的
在Qt下,插件有两种形式,一种是用于QtCreator下,扩展IDE功能.另一种是用于扩展开发者的应用.本文要讲的是后者. 定义一个纯虚类作为插件接口 #include <QtPlugin> ...
- Qt使用第三方库3rdparty
简述 在 Qt 中经常会用到第三方库,例如:FFmpeg.OpenCV 等.第三方库的使用比较简单,只需要一些基本的配置就可以搞定,一起来看看吧! 简述 第三方库 源代码 库文件 目标目录 第三方库 ...