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]). ...
随机推荐
- js 操作样式
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...
- c#中的访问修饰符Protected,privet ,public, internal,和internal protected
Protected,privet ,public, internal,和internal protected的区别 Private修饰的,只能值类内部使用,外部不可以使用,子类不能直接访问,但可以通过 ...
- 获取同时间段不同的时间 php
/** * 根据指定日期返回经过的年月 * @param string $sDay 开始日期 * @param string $eDay 结束日期 * @returnse multitype:stri ...
- 在2005年,Unicode 的第十万个字符被采纳且认可成为标准之一(超过这65535范围的Unicode字符,则需要使用一些诡异的技巧来实现)
在计算机科学领域中,Unicode(统一码.万国码.单一码.标准万国码)是业界的一种标准,它可以使电脑得以体现世界上数十种文字的系统.Unicode 是基于通用字符集(Universal Charac ...
- String的本质是一个char*,只是以类的形式提供,使用起来比较方便
String的本质是一个char*,只是以类的形式提供,使用起来比较方便 Class String {private: char* m_data;}摘自<后台开发 核心技术与应用实践__徐晓鑫& ...
- Win10《芒果TV》商店版更新v3.2.4:新增跨年事件直播、电视台直播,新年快乐
听说半个娱乐圈都来了,<芒果TV>UWP版邀您一起,于2016年12月31日晚,观看<湖南卫视2016·2017跨年演唱会>直播,请更新v3.2.4版,主要新增大事件直播和电视 ...
- Win10《芒果TV》跨年邀你嗨唱,同步直播《湖南卫视2017-2018跨年演唱会》
由天天兄弟.快本家族联袂主持,不容错过的年度盛典<湖南卫视2017-2018跨年演唱会>将于2017年12月31日19:30起由芒果TV同步直播,果妈备上礼物邀您一起跨年嗨唱. 跨年邀你嗨 ...
- SynchronizationContext笔记
SynchronizationContext 类是一个基类,可提供不带同步的自由线程上下文. 此类实现的同步模型的目的是使公共语言运行库内部的异步/同步操作能够针对不同的异步模型采取正确的行为.此模型 ...
- Android零基础入门第69节:ViewPager快速实现引导页
在很多APP第一次启动时都会出现引导页,在一些APP里面还会包括一些左右滑动翻页和页面轮播切换的情况.在之前也已经学习了AdapterViewFlipper和ViewFlipper,都可以很好的实现, ...
- Windows XP 每次开机都自动检测硬盘 解决办法(可以用HDDRegenerate修复坏道)
Windows XP,每次开机都自动检测硬盘,之前正常关机,没有任何非法操作.Windows XP,每次开机都自动检测硬盘,之前正常关机,没有任何非法操作. 1.和硬盘的分区格式有关,FAT32格式在 ...