首页 技术 正文
技术 2022年11月16日
0 收藏 606 点赞 3,394 浏览 2265 个字

BUY LOW, BUY LOWER

Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 7748   Accepted: 2678

Description

The advice to “buy low” is half the formula to success in the bovine stock market.To be considered a great investor you must also follow this problems’ advice:

                    "Buy low; buy lower"

Each time you buy a stock, you must purchase it at a lower price than the previous time you bought it. The more times you buy at a lower price than before, the better! Your goal is to see how many times you can continue purchasing at ever lower prices.

You will be given the daily selling prices of a stock (positive 16-bit integers) over a period of time. You can choose to buy stock on any of the days. Each time you choose to buy, the price must be strictly lower than the previous time you bought stock. Write a program which identifies which days you should buy stock in order to maximize the number of times you buy.

Here is a list of stock prices:

 Day   1  2  3  4  5  6  7  8  9 10 11 12

Price 68 69 54 64 68 64 70 67 78 62 98 87

The best investor (by this problem, anyway) can buy at most four times if each purchase is lower then the previous purchase. One four day sequence (there might be others) of acceptable buys is:

Day    2  5  6 10

Price 69 68 64 62

Input

* Line 1: N (1 <= N <= 5000), the number of days for which stock prices are given

* Lines 2..etc: A series of N space-separated integers, ten per line except the final line which might have fewer integers.

Output

Two integers on a single line: 
* The length of the longest sequence of decreasing prices 
* The number of sequences that have this length (guaranteed to fit in 31 bits)

In counting the number of solutions, two potential solutions are considered the same (and would only count as one solution) if they repeat the same string of decreasing prices, that is, if they “look the same” when the successive prices are compared. Thus, two different sequence of “buy” days could produce the same string of decreasing prices and be counted as only a single solution.

Sample Input

12
68 69 54 64 68 64 70 67 78 62
98 87

Sample Output

4 2
题目大意:求最长下降子序列,并求出子序列的种数。
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;int main()
{
int times[];
int dp[];
int num[];
int n;
int ans, time;
while(scanf("%d", &n) != EOF)
{
ans = ;
time = ;
for (int i = ; i < n; i++)
{
cin>>num[i];
dp[i] = ;
times[i] = ;
}
for (int i = ; i < n; i++)
{
for (int j = i - ; j >= ; j--)
{
if (num[j] > num[i])
{
if (dp[j] + > dp[i])
{
dp[i] = dp[j] + ;
times[i] = times[j];
}
else
{
if (dp[j] + == dp[i])
{
times[i] += times[j];
}
}
}
else
{
if (num[i] == num[j])
{
if (dp[i] == )
{
times[i] = ;
}
break;
}
}
}
}
for (int i = ; i < n; i++)
{
ans = max(ans, dp[i]);
}
for (int i = ; i < n; i++)
{
if (ans == dp[i])
{
time += times[i];
}
}
printf("%d %d\n", ans, time);
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,991
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,505
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844