当前位置:网站首页>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
边栏推荐
- Singleton mode encapsulates activity management class
- Pseudo class elements -- before and after
- ConstraintLayout官方提供圆角ImageFilterView
- > Could not create task ‘:app:MyTest.main()‘. > SourceSet with name ‘main‘ not found.问题修复
- Golang应用专题 - channel
- 学习笔记5--高精地图解决方案
- DDOS攻击原理,被ddos攻击的现象
- @JsonAdapter注解使用
- NCP1342芯片替代料PN8213 65W氮化镓充电器方案
- 非技術部門,如何參與 DevOps?
猜你喜欢
![[paper reading] kgat: knowledge graph attention network for recommendation](/img/fa/d2061bc7bd437f062d46a009cf32cf.png)
[paper reading] kgat: knowledge graph attention network for recommendation

手机厂商“互卷”之年:“机海战术”失灵,“慢节奏”打法崛起

uniapp + uniCloud+unipay 实现微信小程序支付功能

Secteur non technique, comment participer à devops?

风控模型启用前的最后一道工序,80%的童鞋在这都踩坑

In the year of "mutual entanglement" of mobile phone manufacturers, the "machine sea tactics" failed, and the "slow pace" playing method rose
![[论文阅读] KGAT: Knowledge Graph Attention Network for Recommendation](/img/fa/d2061bc7bd437f062d46a009cf32cf.png)
[论文阅读] KGAT: Knowledge Graph Attention Network for Recommendation

> Could not create task ‘:app:MyTest.main()‘. > SourceSet with name ‘main‘ not found.问题修复

Uni app running to wechat development tool cannot Preview

Have you learned to make money in Dingding, enterprise micro and Feishu?
随机推荐
[vite] 1371 - develop vite plug-ins by hand
Learning II of workmanager
Shortcut keys for vscode
ConstraintLayout官方提供圆角ImageFilterView
Constraintlayout officially provides rounded imagefilterview
LDAP概述
WorkManager的学习二
爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
微信小程序触底加载与下拉刷新的实现
The Alipay in place function can't be found, and the Alipay in place function is offline
【SWT组件】内容滚动组件 ScrolledComposite
Learning notes 5 - high precision map solution
Go项目实战—参数绑定,类型转换
学习笔记4--高精度地图关键技术(下)
学习笔记6--卫星定位技术(上)
[论文阅读] KGAT: Knowledge Graph Attention Network for Recommendation
How to write high-quality code?
Have the bosses ever encountered such problems in the implementation of flinksql by Flink CDC mongdb?
Interview: is bitmap pixel memory allocated in heap memory or native
How can non-technical departments participate in Devops?