hdu1087 Super Jumping! Jumping! Jumping!---基础DP---递增子序列最大和
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1087
题目大意:
求递增子序列最大和
思路:
直接dp就可以求解,dp[i]表示以第i位结尾的递增子序列最大和,初始化dp[i] = a[i],转移方程dp[i] = max(dp[i], a[i] + dp[j])如果j < i && a[j] < a[i]
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
int cases;
const int maxn = 1e5 + ;
typedef long long ll;
int n;
int a[maxn], dp[maxn];//dp[i]表示以第i位结尾的最大上升序列和
//dp[i] = max(dp[i], a[i] + dp[j])如果j < i && a[j] < a[i]
int main()
{
while(cin >> n && n)
{
for(int i = ; i < n; i++)
{
cin >> a[i];
dp[i] = a[i];
}
for(int i = ; i < n; i++)
{
for(int j = ; j < i; j++)
{
if(a[j] < a[i])dp[i] = max(dp[i], a[i] + dp[j]);
}
}
int ans = dp[];
for(int i = ; i < n; i++)ans = max(ans, dp[i]);
cout<<ans<<endl;
}
return ;
}
hdu1087 Super Jumping! Jumping! Jumping!---基础DP---递增子序列最大和的更多相关文章
- [GRYZ2014]递增子序列最大和
[问题描述] 给定长度为n的正整数序列a1,a2,…,an. 求一个递增的子序列,和最大. [输入] 第一行,n,表示给定序列的个数. 第二行,n个用空格隔开的正整数. [输出] 递增子序列的最大和. ...
- HDU 1087 Super Jumping....(动态规划之最大递增子序列和)
Super Jumping! Jumping! Jumping! Problem Description Nowadays, a kind of chess game called “Super Ju ...
- Super Jumping! Jumping! Jumping(最大递增子序列的和)
Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. May ...
- HDU 1087 Super Jumping! Jumping! Jumping! 最大递增子序列
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- 「kuangbin带你飞」专题十二 基础DP
layout: post title: 「kuangbin带你飞」专题十二 基础DP author: "luowentaoaa" catalog: true tags: mathj ...
- HDU 1087 简单dp,求递增子序列使和最大
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- kuangbin带你飞dp专题-基础dp
dp HDU - 1257 最少拦截系统 最长递增子序列 #include<iostream> using namespace std; const int maxn=1e7; int a ...
- kuangbin 基础DP集合
HDU 1024第一遍水过,没有体会到这个题的奥妙,思考了很久终于体会了.大概意思是求把序列分成m段的子序列,并不一定要覆盖完,求子序列和的最大值我们首先要写出基本的动态转移方程: DP:dp[ i ...
- 基础dp
队友的建议,让我去学一学kuangbin的基础dp,在这里小小的整理总结一下吧. 首先我感觉自己还远远不够称为一个dp选手,一是这些题目还远不够,二是定义状态的经验不足.不过这些题目让我在一定程度上加 ...
随机推荐
- Microsoft AI - Custom Vision
概述 前几天的 Windows Developer Day 正式发布了 Windows AI Platform,而作为 Windows AI Platform 的模型定义和训练,更多还是需要借助云端来 ...
- 剑指Offer-构建乘积数组
package Array; import sun.security.util.Length; /** * 构建乘积数组 * 给定一个数组A[0,1,...,n-1],请构建一个数组B[0,1,... ...
- 【原创】开启PowerShell远程管理
非域网络,开启PowerShell远程管理,命令如下: 以下操作,PS命令窗口,必须都以管理员省份执行. Step 1: 机器A和B,分别开启PowerShell远程管理服务A = 192.168.3 ...
- 常用的Maven依赖
一.数据库类型 1.mysql驱动 <!-- mysql驱动支持 --> <dependency> <groupId>mysql</groupId> & ...
- 笔记:MyBatis XML配置-Settings 完整属性表
设置参数 描述 有效值 默认值 cacheEnabled 该配置影响的所有映射器中配置的缓存的全局开关. true | false true lazyLoadingEnabled 延迟加载的全局开关. ...
- ~psd面试 求最长回文序列 DP求解
链接:https://www.nowcoder.com/acm/contest/90/D来源:牛客网 掌握未来命运的女神 psd 师兄在拿了朝田诗乃的 buff 后决定去实习. 埃森哲公司注册成立于爱 ...
- LeetCode --> 771. Jewels and Stones
Jewels and Stones You're given strings J representing the types of stones that are jewels, and S rep ...
- [bzoj1707]tanning分配防晒霜_贪心+排序
tanning分配防晒霜 bzoj-1707 题目大意:给出每个点所能接受的区间,给出m个可以使单个点固定在一个值的方法,每种方法能使用有限次. 注释:1<=N<=2500 想法:这题是瞎 ...
- [bzoj3173]最长上升子序列_非旋转Treap
最长上升子序列 bzoj-3173 题目大意:有1-n,n个数,第i次操作是将i加入到原有序列中制定的位置,后查询当前序列中最长上升子序列长度. 注释:1<=n<=10,000,开始序列为 ...
- PHP-CGI,FASTcgi,php-fpm,之间的关系?
刚开始对这个问题我也挺纠结的,看了<HTTP权威指南>后,感觉清晰了不少.首先,CGI是干嘛的?CGI是为了保证web server传递过来的数据是标准格式的,方便CGI程序的编写者. ...