虽然之前学过一点点,但是还是不会------现在好好跟着白书1.4节学一下——————

(1)数字三角形

d(i,j) = max(d(i+1,j),d(i+1,j+1)) + a[i][j]

hdu 2084

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int d[][],a[][]; int main(){
int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
memset(d,,sizeof(d));
for(int i = ;i<=n;i++)
for(int j = ;j<=i;j++) scanf("%d",&a[i][j]); for(int i = n;i>=;i--){
for(int j = ;j<=i;j++)
d[i][j] = max(d[i+][j],d[i+][j+]) + a[i][j];
}
printf("%d\n",d[][]);
}
return ;
}

(2)嵌套矩形

把图先建出来,然后d(i) = max(d(j) + 1)

nyoj 16

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int g[][];
int d[];
int n; struct node{
int x,y;
}a[maxn]; int dp(int i){
int& ans = d[i];
if(ans > ) return ans;
ans = ;
for(int j = ;j <= n;j++)
if(g[i][j]) ans = max(ans,dp(j) + ); return ans;
} int work(){
int res = -;
for(int i = ;i <= n;i++) res = max(res,dp(i));
return res;
} int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
for(int i = ;i <= n;i++) scanf("%d %d",&a[i].x,&a[i].y);
memset(g,,sizeof(g));
memset(d,,sizeof(d)); for(int i = ;i <= n;i++){
for(int j = ;j <= n;j++){
if((a[i].x > a[j].x && a[i].y > a[j].y) || (a[i].x > a[j].y && a[i].y > a[j].x ))
g[i][j] = ;
}
} printf("%d\n",work());
}
return ;
}

Book 动态规划的更多相关文章

  1. 增强学习(三)----- MDP的动态规划解法

    上一篇我们已经说到了,增强学习的目的就是求解马尔可夫决策过程(MDP)的最优策略,使其在任意初始状态下,都能获得最大的Vπ值.(本文不考虑非马尔可夫环境和不完全可观测马尔可夫决策过程(POMDP)中的 ...

  2. 简单动态规划-LeetCode198

    题目:House Robber You are a professional robber planning to rob houses along a street. Each house has ...

  3. 动态规划 Dynamic Programming

    March 26, 2013 作者:Hawstein 出处:http://hawstein.com/posts/dp-novice-to-advanced.html 声明:本文采用以下协议进行授权: ...

  4. 动态规划之最长公共子序列(LCS)

    转自:http://segmentfault.com/blog/exploring/ LCS 问题描述 定义: 一个数列 S,如果分别是两个或多个已知数列的子序列,且是所有符合此条件序列中最长的,则 ...

  5. C#动态规划查找两个字符串最大子串

     //动态规划查找两个字符串最大子串         public static string lcs(string word1, string word2)         {            ...

  6. C#递归、动态规划计算斐波那契数列

    //递归         public static long recurFib(int num)         {             if (num < 2)              ...

  7. 动态规划求最长公共子序列(Longest Common Subsequence, LCS)

    1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...

  8. 【BZOJ1700】[Usaco2007 Jan]Problem Solving 解题 动态规划

    [BZOJ1700][Usaco2007 Jan]Problem Solving 解题 Description 过去的日子里,农夫John的牛没有任何题目. 可是现在他们有题目,有很多的题目. 精确地 ...

  9. POJ 1163 The Triangle(简单动态规划)

    http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  10. hdu FatMouse's Speed 动态规划DP

    动态规划的解决方法是找到动态转移方程. 题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3&sectionid ...

随机推荐

  1. 00--C++牛人的博客

    那些C++牛人的博客 这篇文章来自转载,转载的网址找不到了,   如果有人知道,可以在下面评论,   非常感谢,更感谢原作者. 现整理收集C++世界里那些“牛人”的个人博客.凡三类:一是令人高山仰止的 ...

  2. 实现数组类(C++ 拷贝构造函数、拷贝函数)要判断赋值左右对象不相等,坑惨了

    #include <iostream> using namespace std; class ArrayIndexOutOfBoundsException{ // 异常类 public: ...

  3. Centos7 单节点安装 FastDFS + FastDHT服务

    Centos7 单节点安装 FastDFS + FastDHT服务 1.安装gcc(编译时需要) FastDFS是C语言开发,安装FastDFS需要先将官网下载的源码进行编译,编译依赖gcc环境,如果 ...

  4. 洛谷P1120 小木棍 [数据加强版]搜索

    玄学剪支,正好复习一下搜索 感觉搜索题的套路就是先把整体框架打出来,然后再一步一步优化剪枝 1.从maxv到sumv/2枚举长度(想一想,为什么) 2. 开一个桶,从大到小开始枚举 3. 在搜索中,枚 ...

  5. SQLServer Oracle MySQL的区别

    table tr:nth-child(odd){ background: #FFFFCC; font-size: 18px; } table tr:nth-child(even){ backgroun ...

  6. git入坑随笔

    一直以来,都喜欢用git做版本管理,主要涉及平台是coding, github以及公司自己搭建的gitlab. 因为一直以来都是自己一个人维护前端的项目,所以基本上很少有冲突的情况.(手动微笑 :) ...

  7. ios风格的时间选择插件

    1.起因 在上个项目中,客户希望时间选择插件可以是ios风格的那种,但是找了很久,发现并没有用vue的ios风格时间插件,于是自己便自己造了一个轮子. 2.插件效果 3.插件依赖以及安装使用 插件依赖 ...

  8. [2] day 02

    1. df.memory_usage()将返回每列占用多少 要包含索引,请传递index=True所以要获得整体内存消耗: 2. numpy.iinfo 3. shift函数 https://blog ...

  9. 关于IP数据包首部校验字段的理解

    关于IP数据包首部校验字段的理解 IP数据包格式及首部个字段:  www.2cto.com   对上表的各个数据项就不一一解释了,这里具体关注以下几个数据项: 1.4位首部长度:这里的长度指的是4By ...

  10. @value 注解获取属性文件中的值

    一.属性文件 db.properties name=jack 二.配置文件 applicationContext.xml <!-- 加载配置文件,该节点只能存在一个,所以用 * ,加载所有属性文 ...