当前位置:网站首页>7-2 求解买股票问题
7-2 求解买股票问题
2022-06-24 19:44:00 【白—】
7-2 求解买股票问题
“逢低吸纳”是炒股的一条成功秘诀,如果你想成为一个成功的投资者,就要遵守这条秘诀。“逢低吸纳,越低越买”,这句话的意思是每次你购买股票时的股价一定要比你上次购买时的股价低。按照这个规则购买股票的次数越多越好,看看你最多能按这个规则买几次。
输入格式:
第1行为正整数N(1≤N≤5000)表示能买股票的天数;第2行以下是N个正整数,第i个正整数表示第i天的股价。
12
68 69 54 64 68 64 70 67 78 62 98 87
输出格式:
输出一行表示能够买进股票的最多天数。
4
代码:
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int a[n],c[n],max=-1;
for(int i=0; i<n; i++)
{
scanf("%d",&a[i]);
c[i]=1;
}
for(int i=0;i<n;i++)
{
for(int j=i-1;j>=0;j--)
{
if(a[i]<a[j]&&c[i]<=c[j]+1)
c[i]=c[j]+1;
if(c[i]>max)
max=c[i];
}
}
printf("%d",max);
}
202206222057三
边栏推荐
- [JS] - [linked list - application] - learning notes
- R语言使用MatchIt包进行倾向性匹配分析、使用match.data函数构建匹配后的样本集合、对匹配后的样本的不同分组对应的目标变量的均值进行Welch双样本t检验分析、双独立样本t检验
- 【js】-【數組、棧、隊列、鏈錶基礎】-筆記
- Financial management [1]
- 伪原创智能改写api百度-收录良好
- Mousse shares listed on Shenzhen Stock Exchange: becoming popular by mattress and "foreign old man", with a market value of 22.4 billion yuan
- 慕思股份深交所上市:靠床垫和“洋老头”走红 市值224亿
- 斐波那契
- Online group chat and dating platform test point
- Blogs personal blog test point (manual test)
猜你喜欢

安装IBM CPLEX学术版 academic edition | conda 安装 CPLEX

还在用 SimpleDateFormat 做时间格式化?小心项目崩掉

#22Map介绍与API

【js】-【數組、棧、隊列、鏈錶基礎】-筆記

Main cause of EMI - mold current

【基础知识】~ 半加器 & 全加器

记录一下MySql update会锁定哪些范围的数据

Still using simpledateformat for time formatting? Be careful of project collapse

File contains vulnerability issues

Theoretical analysis of countermeasure training: adaptive step size fast countermeasure training
随机推荐
R语言使用glm函数构建泊松对数线性回归模型处理三维列联表数据构建饱和模型、使用summary函数获取模型汇总统计信息、解读模型系数交互作用及其显著性
idea创建模块提示已存在
Écoutez le fichier markdown et mettez à jour Hot next. Page JS
The R language uses the matchit package for propensity matching analysis and match The data function constructs the matched sample set, and performs Welch double sample t-test analysis and double inde
257. detention of offenders
Docker-mysql8-master-slave
The R language uses the matchit package for propensity matching analysis and match The data function constructs the matched sample set, and judges the balance of all covariates in the sample after the
15 lines of code using mathematical formulas in wangeditor V5
Financial management [1]
【js】-【字符串-应用】- 学习笔记
宁德时代定增450亿:高瓴认购30亿 曾毓群仍控制23%股权
选择类排序法
Building Survey [1]
Pseudo original intelligent rewriting API Baidu - good collection
Force deduction solution summary 515- find the maximum value in each tree row
[JS] - [tree] - learning notes
[JS] - [linked list - application] - learning notes
【js】-【栈、队-应用】-学习笔记
常用正则表达式
R language uses the aggregate function of epidisplay package to split numerical variables into different subsets based on factor variables, calculate the summary statistics of each subset, and customi