Stock Wave+csuoj+简单dp
来源:互联网 发布:有蛇精吐火的软件 编辑:程序博客网 时间:2024/06/05 15:01
Stock Wave
Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 45 Solved: 9
[Submit][Status][Web Board]
Description
As a stock analyst, Tom can forecast the trend according to a series of historical prices. To find the "Wave" is the first thing that he needs to do.
A "Wave" is a series of prices, the value in even place is greater than the former one, and the value in odd place is less than the former one. If you draw these values in one curve, you will see "up, down, up, down ...." Yes, it is a "Wave".
Can you help Tom to find out the longest "Wave"?
Input
The first line of each case is a positive integer n (n < 1000). The next n line(s) is a price with two decimal places.
Output
Print the length of the longest "Wave" in the input, if the length is less than 3, output '0'.
Sample Input
51.008.103.005.004.00 41.012.023.034.04
Sample Output
50
HINT
The longest "Wave" is a subsequence of initial price series, the neighboring values of "Wave" may be NOT neighboring in the original series, but they must keep order of input.
#include <iostream>#include<cstdio>#include<cstring>using namespace std;const int maxn=1005;double L[maxn];int dp[maxn];int main(){ int n; while(~scanf("%d",&n)) { for(int i=1; i<=n; i++) { scanf("%lf",&L[i]); dp[i]=1; } int Max=0; for(int i=2; i<=n; i++) { for(int j=1; j<i; j++) { if(dp[j]%2==0&&L[i]<L[j]) { dp[i]=max(dp[i],dp[j]+1); if(dp[i]>Max) Max=dp[i]; } if(dp[j]%2!=0&&L[i]>L[j]) { dp[i]=max(dp[i],dp[j]+1); if(dp[i]>Max) Max=dp[i]; } } } if(Max>=3) printf("%d\n",Max); else printf("0\n"); } return 0;}
- Stock Wave+csuoj+简单dp
- [简单DP] uva12951 Stock Market
- 简单dp hdu-4105-Electric wave
- Random Integers+csuoj+dp
- hdu6078 wave sequence dp
- CSUOJ
- CSUOJ
- CSUOJ 1729 齿轮传动(基础DP)
- CSUOJ 1592 石子归并(区间DP)
- hdu 4105 Electric wave (dp)
- CSUOJ 1299 - Number Transformation II 打表预处理水DP
- Qz’s Maximum All One Square+csuoj+dp
- CSUOJ-1980: 不堪重负的树(区间DP)
- 【DP】简单【121. Best Time to Buy and Sell Stock】【303. Range Sum Query
- hdu 4105 Electric wave(dp)
- 【DP】 HDOJ 3357 Stock Chase
- CSUOJ 1945 最简单的题目 背包问题
- wave
- 天气API-----开源免费天气预报接口API以及全国所有地区代码!!(国家气象局提供)
- Ubuntu 两台电脑用网线搭建一个局域网(学习笔记)
- C++ STL中顺序容器类型以及实现原理
- 剑指offer中替换空格为"%20"
- 一个非常好用的visual studio 代码对齐插件 Code alignment
- Stock Wave+csuoj+简单dp
- Android实现ListView异步加载图片
- __I、 __O 、__IO
- nginx学习九 高级数据结构之红黑树ngx_rbtree_t
- 数据库连接池的使用(C3P0实现多数据源的数据库连接池)
- linux脚本编程---循环体while和条件语句if then
- 十六进配色表
- UVa 450题记录
- Linux进程与多线程