[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\))的序列,并求出最长下降子序列的长度及个数, 并且,如果两个序列中元素的权值完全相同,那么即使它们的位置不一样,也只算一种 ...
随机推荐
- 在Azure DevOps Server中运行基于Spring Boot和Consul的微服务项目单元测试
1 概述 谈到微服务架构体系,绕不开服务发现这个功能.服务发现机制是简化微服务配置.实现容灾.水平扩缩容.提高运维效率的重要方式.在服务发现工具中,Consul在部署和使用方面与容器结合的天衣无缝,成 ...
- (三十七)golang--如何获取命令行参数
1.第一种方式 缺点:参数的接收受输入的顺序所影响. 2.第二种方式(使用flag包)
- Java连载1-概述&常用的dos命令
本想写完那两个再开始新的,然而客观条件不允许,之前从未接触过Java,从零开始吧!!! 一.概述 C盘下:programme file 一般为64位程序安装的目录,programme file(X ...
- oracle like模糊查询不能走索引?
这里要纠正一个网上很多教程说的模糊匹配不能走索引的说法,因为在看<收获,不止SQL优化>一书,里面举例说到了,并且自己也跟着例子实践了一下,确实like一些特殊情况也是可以走索引的 例子来 ...
- JavaScript DOM 常用操作
1.理解DOM: DOM(Document Object Model ,文档对象模型)一种独立于语言,用于操作xml,html文档的应用编程接口. 怎么说,我从两个角度理解: 对于JavaScript ...
- tensorflow之tf.squeeze()
tf.squeeze()函数的作用是从tensor中删除所有大小(szie)是1的维度. 给定丈量输入, 此操作返回的是相同类型的张量, 并删除所有尺寸为1的维度.如果不想删除所有尺寸为1的维度, 可 ...
- Tomcat 简单容器化
Tomcat 容器化 思考 问题1 , Tomcat 容器化,Tomcat 如何配置 APR 连接器 Tomcat 的基础镜像已经是开启了 APR. 问题2, Tomcat 是每次都需要重新构建. 一 ...
- laravel Method Illuminate\Validation\Validator::validateReuqired does not exist.
Method Illuminate\Validation\Validator::validateReuqired does not exist. 此错误是由于我们在配置验证时,写错了关键字, publ ...
- js实现复制功能兼容ios
html: <div id="copyBT">这是要复制的1内容</div> <a id="contentas">这是复制按 ...
- SAP 同一个序列号可以同时出现在2个不同的HU里?
SAP 同一个序列号可以同时出现在2个不同的HU里? 答案是可以的. 如下图示,HU 180141003288里的序列号11810010540121, 而序列号11810010540121已经出现在另 ...