[POJ1952]BUY LOW, BUY LOWER
|
题目描述 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 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 |
|
输入描述 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: 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 |
|
样例输出 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 ;
}
总结:
[POJ1952]BUY LOW, BUY LOWER的更多相关文章
- POJ-1952 BUY LOW, BUY LOWER(线性DP)
BUY LOW, BUY LOWER Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 9244 Accepted: 3226 De ...
- poj1952 BUY LOW, BUY LOWER【线性DP】【输出方案数】
BUY LOW, BUY LOWER Time Limit: 1000MS Memory Limit: 30000K Total Submissions:11148 Accepted: 392 ...
- USACO Section 4.3 Buy low,Buy lower(LIS)
第一眼看到题目,感觉水水的,不就是最长下降子序列嘛!然后写……就呵呵了..要判重,还要高精度……判重我是在计算中加入各种判断.这道题比看上去麻烦一点,但其实还好吧.. #include<cstd ...
- USACO 4.3 Buy Low, Buy Lower
Buy Low, Buy Lower The advice to "buy low" is half the formula to success in the stock mar ...
- 洛谷P2687 [USACO4.3]逢低吸纳Buy Low, Buy Lower
P2687 [USACO4.3]逢低吸纳Buy Low, Buy Lower 题目描述 “逢低吸纳”是炒股的一条成功秘诀.如果你想成为一个成功的投资者,就要遵守这条秘诀: "逢低吸纳,越低越 ...
- POJ 1952 BUY LOW, BUY LOWER 动态规划题解
Description The advice to "buy low" is half the formula to success in the bovine stock mar ...
- Buy Low, Buy Lower
Buy Low, Buy Lower 给出一个长度为N序列\(\{a_i\}\),询问最长的严格下降子序列,以及这样的序列的个数,\(1 <= N <= 5000\). 解 显然我们可以很 ...
- BUY LOW, BUY LOWER_最长下降子序列
Description The advice to "buy low" is half the formula to success in the bovine stock mar ...
- 题解 【POJ1952】 BUY LOW, BUY LOWER
题目意思: 给你一个长度为\(n\)(\(1<=n<=5000\))的序列,并求出最长下降子序列的长度及个数, 并且,如果两个序列中元素的权值完全相同,那么即使它们的位置不一样,也只算一种 ...
随机推荐
- 解决python 缺少os.fspath
在python3.6下运行pandas会报错缺少os.fspath 升级到python3.7 3.7 安装参考:https://www.cnblogs.com/jifeng/p/11221469.ht ...
- LeetCode 94:二叉树的中序遍历 Binary Tree Inorder Traversal
题目: 给定一个二叉树,返回它的中序 遍历. Given a binary tree, return the inorder traversal of its nodes' values. 示例: 输 ...
- 连接树莓派中的MySQL服务器
今天用笔记本连接树莓派的 MySQL ,结果连接不上.就直接连接到树莓派上进行操作.其实以前也知道远程访问 MySQL 需要进行配置,可以直接 mysql.user 表,也可以直接使用授权的 SQL ...
- 【UOJ#308】【UNR#2】UOJ拯救计划
[UOJ#308][UNR#2]UOJ拯救计划 题面 UOJ 题解 如果模数很奇怪,我们可以插值一下,设\(f[i]\)表示用了\(i\)种颜色的方案数. 然而模\(6\)这个东西很有意思,\(6=2 ...
- Logstash:多个配置文件(conf)
Logstash:多个配置文件(conf) 对于多个配置的处理方法,有多个处理方法: 多个pipeline 一个pipleline处理多个配置文件 一个pipeline含有一个逻辑的数据流,它从inp ...
- Zabbix 设置自动添加主机两种方法(自动注册、自动发现)
在实际生产环境中,我们可能需要将很多台主机添加到 Zabbix Server 里,我们进行手动添加的话,会比较麻烦.费时,而且还容易出错.所以一般我们会设置主机自动注册.这样就比较方便. 官方文档链接 ...
- 扫描不同域下的AD账户进行删除
public ResultModel GetEntryOneToDel(string sAMAccountName) { bool del=false; ResultModel result = ne ...
- Delphi Webbrowser使用方法详解
1.webbroser介绍 该组件是一个浏览器组件,可以显示一个指定地址的网页.设置网页打开时的主页以及对网页进行相关的操作,同时也可以对HTML文件进行剪切.复制.粘贴.删除等操作.该 组件在Int ...
- 关于创建node服务
1.环境条件准备: A.确定node已经创建 B.npm或cnpm已经下载,npm和cnpm其实是一个道理 C.mysql或者使用其他数据库已经安装(本例使用mysql) 2.开始创建,首先新建一个文 ...
- web自动化测试
自动化测试主要分为下面三种: 1.单元测试(Unit Test) 对单独的代码块,比如函数进行测试.单元测试是自动化测试的主要形式,也是最基本的形式. 2.集成测试(Integration Test) ...