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

最新文章

  1. spring 事务传播特性 和隔离级别
  2. APP标配控制器:UINavigationController
  3. [CC]CC插件初探
  4. c#操作Excel时,抛出异常:“未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序”
  5. hive学习笔记——表的基本的操作
  6. systemtap 列出所有linux 内核模块与相关函数0
  7. [POJ] 1064 Cable master (二分查找)
  8. 【2017集美大学1412软工实践_助教博客】团队作业4——第一次项目冲刺(Alpha版本)小组 成绩
  9. 【由浅入深理解java集合】(三)——集合 List
  10. CDHtmlDialog探索----WebBrowser扩展和网页Javascript错误处理
  11. Linux下 nfs部署
  12. C# 简单的 Job 作业~
  13. ES6知识整理(2)--变量的解构赋值
  14. windows 系统使用 git 和码云管理代码(本地已有项目)
  15. 操作数组不要只会for循环
  16. 【CF802C】Heidi and Library (hard) 费用流
  17. InvalidateRect(转)
  18. Yii2.0 Gridview为某列增加属性
  19. PHP using mcrypt and store the encrypted in MySQL
  20. html基础1(环境准备、标签)

热门文章

  1. RISC设计原则及基本技术
  2. http --- 从输入URL到页面加载的过程发生了什么?
  3. String methods
  4. POJ 1141 括号匹配 DP
  5. 天津大学各种Latex模板共享链接
  6. RSA不对称加密
  7. selenium自动化框架介绍------unittest版本
  8. POJ1201Intervals(差分约束)
  9. 解决HMC在IE浏览器无法登录的问题(Java Applet的使用问题)
  10. vmware下ubuntu的网络配置