[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\))的序列,并求出最长下降子序列的长度及个数, 并且,如果两个序列中元素的权值完全相同,那么即使它们的位置不一样,也只算一种 ...
随机推荐
- 删除cookie的封装
remove cookie(key,options){ options=options||{}; options.expires=-1; 删除cookie,其实就是修改cookie,将之前设置好的co ...
- 在Ubuntu18.04.2LTS上使用wine安装qq,微信,迅雷,百度网盘,网易云音乐等软件
在Ubuntu18.04.2LTS上使用wine安装qq,微信,迅雷,百度网盘,网易云音乐等软件 一.前言 在Linux上办公有一点一直是大家的痛,那就是这些系统上没有我们常用的一些软件,比如QQ,微 ...
- iOS 一个项目添加多个TARGET
项目开发中会存在测试.正式等不同环境,需对应不同接口Host地址.项目名称等等配置.如果每次只有一个项目target的话每次打包的时候替换会很麻烦,而且容易出错.所以我们可以通过创建多个不同配置的ta ...
- redis集群之Sentinel
目前我们讲的 Redis 还只是主从方案,最终一致性.读者们可思考过,如果主节点凌晨3 点突发宕机怎么办?就坐等运维从床上爬起来,然后手工进行从主切换,再通知所有的程序把地址统统改一遍重新上线么?毫无 ...
- springboot2+shiro+jwt整合
参考:https://www.jianshu.com/p/ef0a82d471d2 https://www.jianshu.com/p/3c51832f1051 https://blog.csdn.n ...
- jdbc:mysql:/// jdbc连接数据url简写方式
正常情况下我们写jdbc连接本地mysql数据库的时候通常是这样写 jdbc:mysql:localhost:3306/数据库名 下面就是要提到的简单的方法 jdbc:mysql:///数据库名
- 用openresty(Lua)写一个获取YouTube直播状态的接口
文章原发布于:https://www.chenxublog.com/2019/08/29/openresty-get-youtube-live-api.html 之前在QQ机器人上面加了个虚拟主播开播 ...
- C# 人民币大写金额转换
/// <summary> /// 转换人民币大小金额 /// </summary> /// <param name="nu ...
- C# .NET 使用 NPOI 读取 .xlsx 格式 Excel
string filePath = @"C:\Users\yangqinglin\Desktop\test.xlsx"; IWorkbook wk = null; string e ...
- 微信和QQ可以关闭广告了,每次能关6个月
微信和QQ可以关闭广告了,这次腾讯真的是良心了,虽然不能完全关闭,但是每次能关6个月,也能清静不少时间. 关闭地址:点击进入