hdu-1087(动态规划)
题目链接: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(动态规划)的更多相关文章
- hdu 1087 动态规划之最长上升子序列
http://acm.hdu.edu.cn/showproblem.php?pid=1087 Online Judge Online Exercise Online Teaching Online C ...
- HDU 1087 简单dp,求递增子序列使和最大
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1069&&HDU 1087 (DP 最长序列之和)
H - Super Jumping! Jumping! Jumping! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format: ...
- HDU 1087 Super Jumping! Jumping! Jumping
HDU 1087 题目大意:给定一个序列,只能走比当前位置大的位置,不可回头,求能得到的和的最大值.(其实就是求最大上升(可不连续)子序列和) 解题思路:可以定义状态dp[i]表示以a[i]为结尾的上 ...
- 怒刷DP之 HDU 1087
Super Jumping! Jumping! Jumping! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64 ...
- (最大上升子序列) Super Jumping! Jumping! Jumping! -- hdu -- 1087
http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit:1000MS ...
- HDU 1087 Super Jumping! Jumping! Jumping! 最长递增子序列(求可能的递增序列的和的最大值) *
Super Jumping! Jumping! Jumping! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64 ...
- hdu 1087 Super Jumping! Jumping! Jumping!(动态规划DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit: 200 ...
- hdu 1087 Super Jumping! Jumping! Jumping!(动态规划DP)
Super Jumping! Jumping! Jumping!Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1087 Super Jumping! Jumping! Jumping!(动态规划)
Super Jumping! Jumping! Jumping! Problem Description Nowadays, a kind of chess game called “Super Ju ...
随机推荐
- 常用HTTP状态码
1.常用状态码介绍 在http响应协议中,我们通过HttpWatch抓包抓取到响应信息.其中响应首行中就包含一个状态码.状态码由三位数字组成,表示请求是否被理解或者被满足.HTTP响应状态码的第一个数 ...
- ios 获得webview user-agent
UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectZero]; NSString *myUserAgent = [webView s ...
- UILabel 自适应高度,宽度
mLabel1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, 10, 1)]; mLabel1.text = @"my label 1, ...
- app.$mount("#app") 手动挂载
$mount()手动挂载 当Vue实例没有el属性时,则该实例尚没有挂载到某个dom中: 假如需要延迟挂载,可以在之后手动调用vm.$mount()方法来挂载.例如: new Vue({ //el: ...
- scala --操作符和运算
基本类型和操作 scala 的基本类型包括如下几种 数类型 整数类型 :Byte Short Int Long 小数类型: Float Double 字符类型:Char 用'' 单引号包裹,是 ...
- R及Rstuio下载及配置,及基本使用介绍
1.R和Rstudio下载地址 https://cran.rstudio.com/a 2.Rstudio 的配置 外观.代码显示比例配置 选中tools 选中globle options 选中appe ...
- 常用数据库ID格式
转自:http://www.biotrainee.com/thread-411-1-1.html 常用数据库 ID ID 示例 ID 来源 ENSG00000116717 Ensemble ID GA ...
- padright padleft
在 C# 中可以对字符串使用 PadLeft 和 PadRight 进行轻松地补位. PadLeft(int totalWidth, char paddingChar) //在字符串左边用 paddi ...
- ThreadPoolExecutor的execute源码分析
上一篇文章指出,ThreadPoolExecutor执行的步骤如下: 向线程池中添加任务,当任务数量少于corePoolSize时,会自动创建thead来处理这些任务: 当添加任务数大于corePoo ...
- C/C++ 宏
0. #define MALLOC(n, type) \ ( (type *) malloc((n)* sizeof(type))) 1. 宏可以像函数一样被定义,例如: #define min ...