题目描述 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 Description

* 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 Description

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

数据范围及提示 Data Size & Hint

 

之前的一些废话:近日诸事不顺。

题解:对于第一问我们xjb做一遍最长下降子序列即可,对于方案数,在转移的时候顺便计算一下,注意如果发现a[i]=a[j],就要把cnt[i]标记成0,来做到去重。

代码:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<set>
#include<queue>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
#define mem(a,b) memset(a,b,sizeof(a))
inline int read()
{
int x=,f=;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-;c=getchar();}
while(isdigit(c)){x=x*+c-'';c=getchar();}
return x*f;
}
const int maxn=;
int n,a[maxn],dp[maxn],ans,cnt,dp2[maxn];
int main()
{
n=read();
for(int i=;i<=n;i++)a[i]=read(),dp[i]=dp2[i]=;
for(int i=;i<=n;i++)
for(int j=;j<i;j++)
{
if(a[i]<a[j])
{
if(dp[j]+>dp[i])dp[i]=dp[j]+,dp2[i]=dp2[j];
else if(dp[j]+==dp[i])dp2[i]+=dp2[j];
}
else if(a[i]==a[j])dp2[i]=;
}
for(int i=;i<=n;i++)ans=max(ans,dp[i]);
for(int i=;i<=n;i++)if(ans==dp[i])cnt+=dp2[i];
printf("%d %d\n",ans,cnt);
return ;
}

总结:

最新文章

  1. Linux下安装和配置JDK与Tomcat(升级版)
  2. 搭建dns域名服务器过程
  3. Python小爬虫练习
  4. WinFrm窗体的传值方式
  5. AJAX 小实例(转摘)
  6. python中functools.wraps装饰器的作用
  7. 上传多张图片用Session临时存储
  8. Android 从硬件到应用程序:一步一步爬上去 5 -- 在Frameworks蒂姆层硬件服务
  9. linux前四天学习笔记
  10. Hibernate入门(五)
  11. Hibernate缓存和状态
  12. ThreadLocal 线程本地变量 及 源码分析
  13. 简述在javascript和jquery中cookie的使用
  14. [Android] Android 锁屏实现与总结 (三)
  15. pandas groupby生成新的dataframe
  16. DIV+CSS详解
  17. android ScrollView 控制行数
  18. Kafka基础系列第1讲:Kafka的诞生背景及应用
  19. DirectoryEntry_Properties属性的遍历(win2008)
  20. org.springframework.orm.hibernate3.LocalSessionFactoryBean

热门文章

  1. R语言算法 ▪ 计算随意输入的两数之间的区域和
  2. C++:Name Lookup &amp; Best Match
  3. redis命令之 ----String(字符串)
  4. Focal Loss tensorflow 实现
  5. mysql启动报错:Failed to start LSB: start and stop MySQL
  6. 【洛谷5439】【XR-2】永恒(树链剖分,线段树)
  7. 【LOJ#3145】[APIO2019]桥梁(分块,并查集)
  8. 升级 ASP.NET Core 3.0 设置 JSON 返回 PascalCase 格式与 SignalR 问题
  9. ASP.NET Core快速入门(第2章:配置管理)--学习笔记
  10. cmd 运行bcp 提示:&#39;bcp&#39; 不是内部或外部命令,也不是可运行的程序 或批处理文件。