UVALive 6867 Plane Ticket Pricing
Time Limit: 3000MS | Memory Limit: Unknown | 64bit IO Format: %lld & %llu |
Description
Plane ticket prices fluctuate wildly from one week to the next, and their unpredictability is a major source of frustration for travellers. Some travellers regret buying tickets too early when the prices drop right after they purchase the tickets, and some travellers regret buying tickets too late when prices rise right before they are about to make the purchase. At the end, no one is happy, except the airlines, of course.
Surely there is some reason to this madness. It turns out that airlines price their tickets dynamically, based on how many seats are still available and how close the flight is. For example, if there are very few seats left on a flight then the tickets may be expensive until the last few weeks before the flight, at which point the prices may decrease to fill the empty seats. Ultimately, the airlines wish to maximize revenue from each flight.
You have been hired by the International Contrived Pricing Corporation (ICPC) to set ticket prices each week for airlines. The airlines have collected and analyzed historical data, and have good estimates on the number of seats that will be sold at a particular ticket price with a particular number of weeks before the flight. Given the number of seats left on a flight as well as the number of weeks left before the flight, your job is to set the ticket price for the current week, in order to maximize the total revenue obtained from ticket sales from the current week to the time of the flight. You may assume that the number of tickets sold is exactly the same as the estimates, unless there are not enough remaining seats. In that case, all remaining seats will be sold. You may also assume that the optimal ticket prices will be chosen for the remaining weeks before the flight.
Note that higher prices do not necessarily mean fewer tickets will be sold. In fact, higher prices can sometimes increase sales as travellers may be worried that the prices will rise even higher later.
Input
The input consists of one case. The first line contains two integers, N and W, the number of seats left and
the number of weeks left before the flight (0 < N 300, 0 W 52). The next W + 1 lines give the
estimates for W weeks, W
Output
On the first line, print the maximum total revenue the airline can obtain from ticket sales from the current
week to the time of the flight. On the second line, print the ticket price to set for the current week (W weeks
before the flight) to achieve this maximum.
If there are multiple sets of ticket prices achieving this maximum, choose the smallest ticket price for week
W.
Sample Input
50 2
1 437 47
3 357 803 830 13 45 46
1 611 14
Sample Output
23029
437
HINT
Source
解题:一道记忆化搜索题 dfs(curn,curw)表示还剩curn张票没卖完,已经是第curw周了
#include <bits/stdc++.h>
using namespace std;
int dp[][],n,w,sels,ans;
vector<int>price[],sales[];
int dfs(int curn,int curw){
if(curn <= || curw < ) return ;
if(dp[curn][curw] != -) return dp[curn][curw];
int ret = ;
for(int i = price[curw].size()-; i >= ; --i){
int tmp = price[curw][i]*min(curn,sales[curw][i]) + dfs(curn - min(curn,sales[curw][i]),curw+);
if(curw == && tmp > ret) ans = price[curw][i];
else if(curw == && tmp == ret) ans = min(ans,price[curw][i]);
ret = max(ret,tmp);
}
return dp[curn][curw] = ret;
}
int main() {
while(~scanf("%d %d",&n,&w)) {
memset(dp,-,sizeof dp);
for(int i = ; i < ; ++i) {
price[i].clear();
sales[i].clear();
}
for(int i = ,tmp; i <= w; ++i) {
scanf("%d",&sels);
for(int j = ; j < sels; ++j) {
scanf("%d",&tmp);
price[i].push_back(tmp);
}
for(int j = ; j < sels; ++j) {
scanf("%d",&tmp);
sales[i].push_back(tmp);
}
}
ans = 0x3f3f3f3f;
printf("%d\n",dfs(n,));
printf("%d\n",ans);
}
return ;
}
/*
100 3
4 195 223 439 852 92 63 15 1
2 811 893 76 27
1 638 3
1 940 38
*/
UVALive 6867 Plane Ticket Pricing的更多相关文章
- Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/context/embedded/ServletRegistrationBean
异常信息 2017-09-02 18:06:37.223 [main] ERROR o.s.boot.SpringApplication - Application startup failed ja ...
- present simple, continuous, and be going to 三者区别
https://www.youtube.com/watch?v=a03VKQL0dZg&list=PLZOJurmtexYozmvQGAJnVg3lgiZw0mj-y HOW TO USE F ...
- [转]TDD之Dummy Stub Fake Mock
TDD之Dummy Stub Fake Mock 测试驱动大家都很熟悉了,这两天正好看了一个java的书,对TDD中的一些基本概念进行了复习,具体如下: Dummy An object that is ...
- 新概念 Lesson 2 Sorry, sir.
Is this your handbag? 这是你的手提包吗? Yes,it is. /No it isn't 人称代词的主格宾格 形容性物主代词的用法 Does the man get his um ...
- 所有selenium相关的库
通过爬虫 获取 官方文档库 如果想获取 相应的库 修改对应配置即可 代码如下 from urllib.parse import urljoin import requests from lxml im ...
- POJ 2296 Map Labeler / ZOJ 2493 Map Labeler / HIT 2369 Map Labeler / UVAlive 2973 Map Labeler(2-sat 二分)
POJ 2296 Map Labeler / ZOJ 2493 Map Labeler / HIT 2369 Map Labeler / UVAlive 2973 Map Labeler(2-sat ...
- UVALive 5099
B - Nubulsa Expo Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit S ...
- UVALive 5099 Nubulsa Expo 全局最小割问题
B - Nubulsa Expo Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit S ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
随机推荐
- SurfaceView左右滑动切换黑屏问题解决方式
在项目中使用的是高德地图,放置MapView的Fragment和其它Fragment放置一个ViewPager中切换:当从MapView的Fragment切换到其它Fragment或者从其它Fragm ...
- Java - 多线程Callable、Executors、Future
http://blog.csdn.net/pipisorry/article/details/44341579 Introduction Callable接口代表一段能够调用并返回结果的代码; Fut ...
- Python: PS 滤镜--碎片特效
本文用 Python 实现 PS 滤镜中的碎片特效,这个特效简单来说就是将图像在 上,下,左,右 四个方向做平移,然后将四个方向的平移的图像叠加起来做平均.具体的效果图可以参考之前的博客 http:/ ...
- 制作 Gif 工具
ScreenToGif:非常小,非常强大: 从此可以十分方便地从视频中抠 gif 出来了: 以及制作一些教学类小 gif,插入到网页中: 丰富的编辑功能: 插入文本,插入标题,插入图像等: 下载地址: ...
- Tuple assignment
It is often useful to swap the values of two variables. With conventional assignments, you have to u ...
- miniUI-SelectGrid 弹出选择表格-翻页选中
介绍 mini中已经给出 弹出表格的里例子 :MiniUi版本 但是在应用过程中遇到写小问题就是没有办法翻页后一并连之前翻页选中的一起提交 以下是解决方案 正文 下面首先介绍 JS 代码 //存储已 ...
- P2264 情书(字符串hash90分)
题目背景 一封好的情书需要撰写人全身心的投入.lin_toto同学看上了可爱的卡速米想对她表白,但却不知道自己写的情书是否能感动她,现在他带着情书请你来帮助他. 题目描述 为了帮助lin_toto,我 ...
- Android属性动画-Interpolator和ViewPropertyAnimator的用法
Interpolator的用法 Interpolator这个东西很难进行翻译,直译过来的话是补间器的意思,它的主要作用是可以控制动画的变化速率,比如去实现一种非线性运动的动画效果.那么什么叫做非线性运 ...
- asp.net网页播放MP4 出错
通过IIS进行添加:单击[开始]→[程序]→[管理工具]→[IIS管 理器],逐步展开“本地计算机”.“网站”,在你的网站上右击,选择[属性],单击“HTTP头”选项卡→单击“MIME类型”按钮,再单 ...
- BZOJ3744 Gty的妹子序列(分块+树状数组)
题意 询问区间内逆序对数 强制在线 1<=n<=50000 1<=m<=50000 题解 两个预处理f[i][j]为块i到j的逆序对数,s[i][j]前i块≤j的有多少个边角 ...