当前位置:网站首页>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
边栏推荐
- Completion report of communication software development and Application
- 伪类元素--before和after
- How to judge that the thread pool has completed all tasks?
- Uni app running to wechat development tool cannot Preview
- 各位大佬,我测试起了3条线程同时往3个mysql表中写入,每条线程分别写入100000条数据,用了f
- StaticLayout的使用详解
- In the year of "mutual entanglement" of mobile phone manufacturers, the "machine sea tactics" failed, and the "slow pace" playing method rose
- > Could not create task ‘:app:MyTest.main()‘. > SourceSet with name ‘main‘ not found.问题修复
- WorkManager学习一
- NAS与SAN
猜你喜欢
【观察】跨境电商“独立站”模式崛起,如何抓住下一个红利爆发时代?
How to write high-quality code?
pytorch输出tensor张量时有省略号的解决方案(将tensor完整输出)
【Vite】1371- 手把手开发 Vite 插件
[paper reading] ckan: collaborative knowledge aware autonomous network for adviser systems
学习笔记6--卫星定位技术(上)
非技術部門,如何參與 DevOps?
【JS】提取字符串中的分数,汇总后算出平均分,并与每个分数比较,输出
Atcoder beginer contest 254 "e BFS" f st table maintenance differential array GCD "
Comparative learning in the period of "arms race"
随机推荐
Learning II of workmanager
Implementation of wechat applet bottom loading and pull-down refresh
[可能没有默认的字体]Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename……
各位大佬,我测试起了3条线程同时往3个mysql表中写入,每条线程分别写入100000条数据,用了f
[observation] with the rise of the "independent station" model of cross-border e-commerce, how to seize the next dividend explosion era?
> Could not create task ‘:app:MyTest.main()‘. > SourceSet with name ‘main‘ not found.问题修复
"Everyday Mathematics" serial 58: February 27
Who is the "conscience" domestic brand?
钉钉、企微、飞书学会赚钱了吗?
@Serializedname annotation use
伪类元素--before和after
学习笔记4--高精度地图关键技术(下)
【js学习笔记五十四】BFC方式
PHP solves the problems of cache avalanche, cache penetration and cache breakdown of redis
ConstraintLayout官方提供圆角ImageFilterView
AtCoder Beginner Contest 254「E bfs」「F st表维护差分数组gcd」
SQL Server 监控统计阻塞脚本信息
九度 1480:最大上升子序列和(动态规划思想求最值)
WorkManager學習一
The horizontally scrolling recycleview displays five and a half on one screen, lower than the average distribution of five