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的更多相关文章

  1. 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 ...

  2. present simple, continuous, and be going to 三者区别

    https://www.youtube.com/watch?v=a03VKQL0dZg&list=PLZOJurmtexYozmvQGAJnVg3lgiZw0mj-y HOW TO USE F ...

  3. [转]TDD之Dummy Stub Fake Mock

    TDD之Dummy Stub Fake Mock 测试驱动大家都很熟悉了,这两天正好看了一个java的书,对TDD中的一些基本概念进行了复习,具体如下: Dummy An object that is ...

  4. 新概念 Lesson 2 Sorry, sir.

    Is this your handbag? 这是你的手提包吗? Yes,it is. /No it isn't 人称代词的主格宾格 形容性物主代词的用法 Does the man get his um ...

  5. 所有selenium相关的库

    通过爬虫 获取 官方文档库 如果想获取 相应的库 修改对应配置即可 代码如下 from urllib.parse import urljoin import requests from lxml im ...

  6. 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 ...

  7. UVALive 5099

    B - Nubulsa Expo Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit S ...

  8. UVALive 5099 Nubulsa Expo 全局最小割问题

    B - Nubulsa Expo Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit S ...

  9. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

随机推荐

  1. SQL Server 2008 备份数据库

    1.打开SQL , 找到要备份的数据库 , 右键 >> 任务 >>备份 2.弹出 [ 备份数据库对话框 ] ,如图: 3.点击加入 [ button ] . 例如以下图: 4. ...

  2. HD-ACM算法专攻系列(2)——Rightmost Digit

    题目描述: 源码: /**/ #include"iostream" using namespace std; int main() { int t, mod; long long ...

  3. HD-ACM算法专攻系列(1)——第几天?

    题目描述: 源码: #include <cstdio> #include <ctime> int main() { int year, month, day; int sum; ...

  4. Android实现App版本自动更新

    现在很多的App中都会有一个检查版本的功能.例如斗鱼TV App的设置界面下: 当我们点击检查更新的时候,就会向服务器发起版本检测的请求.一般的处理方式是:服务器返回的App版本与当前手机安装的版本号 ...

  5. asp.net 项目发布注意点

    在修改了某些代码后,要发布到服务器 这时候 ,在本地发布完把对应的文件复制到服务器上覆盖即可. 1.如果修改的是.cs  .asmx等文件,则需要覆盖其对应项目名称的.dll文件 2.如果修改的是.h ...

  6. Layout Team

    The layout team is a long-term engineering team tasked with maintaining, supporting, and improving t ...

  7. Debian9.5 系统配置FTP

    FTP 是File Transfer Protocol(文件传输协议)的英文简称,而中文简称为“文传协议”.用于Internet上的控制文件的双向传输.同时,它也是一个应用程序(Application ...

  8. caffe for python (官方翻译)

    导言 本教程中,我们将会利用Caffe官方提供的深度模型——CaffeNet(该模型是基于Krizhevsky等人的模型的)来演示图像识别与分类.我们将分别用CPU和GPU来进行演示,并对比其性能.然 ...

  9. 学习Go语言之使用channel避免竞态问题

    // 使用channel避免竞态问题 package main import ( "fmt" "sync" ) var ( i int wg sync.Wait ...

  10. BZOJ 3626 LCA(离线+树链剖分+差分)

    显然,暴力求解的复杂度是无法承受的. 考虑这样的一种暴力,我们把 z 到根上的点全部打标记,对于 l 到 r 之间的点,向上搜索到第一个有标记的点求出它的深度统计答案.观察到,深度其实就是上面有几个已 ...