题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087

思路:每确定一个数,后面一个数肯定比它大。所以可以先从最后一个数开始,不断向前确定前面的状态,推导出

状态转移方程为:dp[i] = dp[i]+max(dp[j]) (j<i&&a[j]<a[i])。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn = ;
int a[maxn],dp[maxn];
int main(void)
{
int i,j,n;
while(~scanf("%d",&n)&&n)
{
for(i=;i<n;i++) scanf("%d",&a[i]);
for(i=;i<n;i++) dp[i]=a[i];
for(i=n-;i>=;i--)
{
int tp=;
for(j=i+;j<n;j++)
{
if(a[j]>a[i]&&dp[j]>tp)
tp=dp[j];
}
dp[i]+=tp;
}
int ans=;
for(i=;i<n;i++)
{
if(ans<dp[i]) ans=dp[i];
}
printf("%d\n",ans);
}
return ;
}

hdu-1087(动态规划)的更多相关文章

  1. hdu 1087 动态规划之最长上升子序列

    http://acm.hdu.edu.cn/showproblem.php?pid=1087 Online Judge Online Exercise Online Teaching Online C ...

  2. HDU 1087 简单dp,求递增子序列使和最大

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  3. HDU 1069&&HDU 1087 (DP 最长序列之和)

    H - Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format: ...

  4. HDU 1087 Super Jumping! Jumping! Jumping

    HDU 1087 题目大意:给定一个序列,只能走比当前位置大的位置,不可回头,求能得到的和的最大值.(其实就是求最大上升(可不连续)子序列和) 解题思路:可以定义状态dp[i]表示以a[i]为结尾的上 ...

  5. 怒刷DP之 HDU 1087

    Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64 ...

  6. (最大上升子序列) Super Jumping! Jumping! Jumping! -- hdu -- 1087

    http://acm.hdu.edu.cn/showproblem.php?pid=1087   Super Jumping! Jumping! Jumping! Time Limit:1000MS  ...

  7. HDU 1087 Super Jumping! Jumping! Jumping! 最长递增子序列(求可能的递增序列的和的最大值) *

    Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64 ...

  8. hdu 1087 Super Jumping! Jumping! Jumping!(动态规划DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit: 200 ...

  9. hdu 1087 Super Jumping! Jumping! Jumping!(动态规划DP)

    Super Jumping! Jumping! Jumping!Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  10. HDU 1087 Super Jumping! Jumping! Jumping!(动态规划)

    Super Jumping! Jumping! Jumping! Problem Description Nowadays, a kind of chess game called “Super Ju ...

随机推荐

  1. discuz 修改积分策略( 在周期中添加"每周" )

    在  source/admincp/admincp_credits.php 文件中, ctrl+f 搜索  $lang['setting_credits_policy_cycletype_1'] 处, ...

  2. 创建类type (底层代码)

    类的创建时是用type 实现的 def __init__(self, name): self.name = name def fun(self): print("%s is talking' ...

  3. springmvc initial初始化

    项目需求是在启动服务时,将某些内容放入到共同里面,例如数据字典表内容. 但数据字典表内容存在于数据库中,使用传统的listener在加载时,无法获取service实例,打开事务控制. springmv ...

  4. Graylog安装配置

    ES集群健康检测:curl -sXGET http://localhost:9200/_cluster/health?pretty=true | grep "status" | a ...

  5. jremoting的功能扩展点

    1  InvokeFilter,实现此接口 可以在consumer端 与provider端的调用过程中拦截住请求调用. 已经实现的InvokeFilter包括 RetryInvokeFilter:实现 ...

  6. python并行编程

    一.编程思想 并行编程的思想:分而治之,有两种模型 1.MapReduce:将任务划分为可并行的多个子任务,每个子任务完成后合并得到结果 例子:统计不同形状的个数. 先通过map进行映射到多个子任务, ...

  7. CSS 折角效果

    1 <style type="text/css"> .div1 { width: 200px; height: 200px; background-color: #ff ...

  8. Retrofit2+Rxjava2 okhttp RxBus 使用记录

    学习 博客 http://blog.csdn.net/r17171709/article/details/51149350 @Query 后面跟要添加的字段 @Path 连接url里面{userId} ...

  9. Spring编程式事务管理

    --------------------siwuxie095                                 Spring 编程式事务管理         以转账为例         ...

  10. [leetcode]426. Convert Binary Search Tree to Sorted Doubly Linked List二叉搜索树转有序双向链表

    Convert a BST to a sorted circular doubly-linked list in-place. Think of the left and right pointers ...