当前位置:网站首页>Nine degrees 1480: maximum ascending subsequence sum (dynamic programming idea for the maximum value)
Nine degrees 1480: maximum ascending subsequence sum (dynamic programming idea for the maximum value)
2022-07-05 10:33:00 【Full stack programmer webmaster】
A sequence of numbers bi, When b1 < b2 < … < bS When , We call this sequence ascending . For a given sequence (a1, a2, …,aN), We can get some ascending subsequences (ai1, ai2, …, aiK), here 1 <= i1 < i2 < … < iK <= N. such as , For the sequence (1, 7, 3, 5, 9, 4, 8), It has some ascending subsequences , Such as (1, 7), (3, 4, 8) wait . The maximum sum of these subsequences is 18, For subsequences (1, 3, 5, 9) And .
Your task , For a given sequence , Find the maximum ascending subsequence and . Be careful , The sum of the longest ascending subsequence is not necessarily the largest , Example sequence (100, 1, 2, 3) The maximum sum of ascending subsequences is 100, The longest ascending subsequence is (1, 2, 3).
Ideas
1.dp[i] Said to i Maximum ascending sequence at the end
dp[i] = max(dp[j]) + value[i]
2. There is no relationship between the longest ascending subsequence and the largest ascending subsequence
3. The idea of this problem is the same as that of the largest continuous subarray
Code
#include <iostream> #include <stdio.h>
using namespace std; int dp[1001]; int val[1001]; int n; int main() { while(scanf("%d", &n) != EOF ) { for(int i = 0; i < n; i ++) scanf("%d", val+i); dp[0] = val[0]; for(int i = 1; i < n; i ++) { dp[i] = val[i]; for(int j = 0; j < i; j ++) { if(val[j] >= val[i]) continue; dp[i] = max(dp[i], dp[j]+val[i]); } } int resval = 0; for(int i = 0; i < n; i ++) resval = max(resval, dp[i]); cout << resval << endl; } return 0; }
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/109896.html Link to the original text :https://javaforall.cn
边栏推荐
- @Serializedname annotation use
- 钉钉、企微、飞书学会赚钱了吗?
- StaticLayout的使用详解
- [论文阅读] KGAT: Knowledge Graph Attention Network for Recommendation
- TSQL–标示列、GUID 、序列
- 风控模型启用前的最后一道工序,80%的童鞋在这都踩坑
- Workmanager Learning one
- Usage differences between isempty and isblank
- Timed disappearance pop-up
- C function returns multiple value methods
猜你喜欢
爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
C language QQ chat room small project [complete source code]
“军备竞赛”时期的对比学习
字节跳动面试官:一张图片占据的内存大小是如何计算
IDEA新建sprintboot项目
Detailed explanation of the use of staticlayout
Solution of ellipsis when pytorch outputs tensor (output tensor completely)
AtCoder Beginner Contest 254「E bfs」「F st表维护差分数组gcd」
ConstraintLayout官方提供圆角ImageFilterView
Apple 5g chip research and development failure? It's too early to get rid of Qualcomm
随机推荐
Glide conclusion
Workmanager learning 1
官网给的这个依赖是不是应该为flink-sql-connector-mysql-cdc啊,加了依赖调
Comparative learning in the period of "arms race"
@JsonAdapter注解使用
SqlServer定时备份数据库和定时杀死数据库死锁解决
@Serializedname annotation use
微信小程序中,从一个页面跳转到另一个页面后,在返回后发现页面同步滚动了
【js学习笔记五十四】BFC方式
[论文阅读] CKAN: Collaborative Knowledge-aware Atentive Network for Recommender Systems
“军备竞赛”时期的对比学习
Who is the "conscience" domestic brand?
ConstraintLayout官方提供圆角ImageFilterView
【JS】提取字符串中的分数,汇总后算出平均分,并与每个分数比较,输出
SQL Server 监控统计阻塞脚本信息
非技術部門,如何參與 DevOps?
Error: module not found: error: can't resolve 'xxx' in 'XXXX‘
DDOS攻击原理,被ddos攻击的现象
SLAM 01.人类识别环境&路径的模型建立
App各大应用商店/应用市场网址汇总