CSU1630: Plane Ticket Pricing
来源:互联网 发布:linux更改用户 编辑:程序博客网 时间:2024/05/22 13:50
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 21 437 473 357 803 830 13 45 461 611 14
Sample Output
23029437
HINT
Source
#include <iostream>#include <stdio.h>#include <string.h>#include <stack>#include <queue>#include <map>#include <set>#include <vector>#include <math.h>#include <bitset>#include <algorithm>#include <climits>using namespace std;#define LS 2*i#define RS 2*i+1#define UP(i,x,y) for(i=x;i<=y;i++)#define DOWN(i,x,y) for(i=x;i>=y;i--)#define MEM(a,x) memset(a,x,sizeof(a))#define W(a) while(a)#define gcd(a,b) __gcd(a,b)#define LL __int64#define N 25#define MOD 1000000007#define INF 0x3f3f3f3f#define EXP 1e-8int n,w;int dp[55][305];//第i天,出售的座位总数为j的收益int path[55][305];//第i天,出售的座位总数为j的第一天的销售价格struct node{ int len,price[305],num[305];}a[55];int main(){ int i,j,k,tem; W(~scanf("%d%d",&n,&w)) { UP(i,1,w+1) { scanf("%d",&a[i].len); UP(j,1,a[i].len) { scanf("%d",&a[i].price[j]); } UP(j,1,a[i].len) { scanf("%d",&a[i].num[j]); } } MEM(dp,-1); UP(i,1,a[1].len) { tem = min(a[1].num[i],n); dp[1][tem]=tem*a[1].price[i]; path[1][tem] = a[1].price[i]; } UP(i,2,w+1) { UP(j,0,n) { if(dp[i-1][j]==-1) continue; UP(k,1,a[i].len) { tem = min(n,j+a[i].num[k]); if(dp[i][tem]<dp[i-1][j]+(tem-j)*a[i].price[k] || (dp[i][tem]==dp[i-1][j]+(tem-j)*a[i].price[k] && path[i][tem]>a[i].price[k])) { path[i][tem]=path[i-1][j]; dp[i][tem]=dp[i-1][j]+(tem-j)*a[i].price[k]; } } } } int s1=-1,s2; UP(i,0,n) { if(s1<dp[w+1][i]) { s1 = dp[w+1][i]; s2 = path[w+1][i]; } } printf("%d\n%d\n",s1,s2); } return 0;}
- CSU1630: Plane Ticket Pricing
- CSUOJ1630--Plane Ticket Pricing
- (朴素dp)C.Plane Ticket Pricing
- Essay 1 : The Plane ticket
- Pricing Mechanism
- Pricing Factors
- 阶梯计价 differential pricing
- Azure Basic - Pricing
- Google Smart Pricing[incomplete]
- Pricing procedure for SD
- Pricing for Commission agent
- Setting up Pricing Agreements
- Pricing Control - 价格控制
- App Store Pricing Matrix
- X-Plane
- Plane Spotting
- plane equation
- Plane Equation
- 深圳初中生约架群殴 家长协调未果加入打斗
- ME21N,ME22N,ME23N之BADI增强ME_PROCESS_PO_CUST
- Linux入门教程
- Rightmost Digit
- sdwebimage
- CSU1630: Plane Ticket Pricing
- 设置修改CentOS系统时区
- MFC radio控件的使用方法
- 【Android】FragmentTabHost实现底部Tab菜单选项
- 透过浏览器看HTTP缓存
- 成都保安阻止小伙偷车 3人拿刀冲进银行追砍(图)
- 1002—列变位法解密
- for和foreach差别
- Spring MVC 框架搭建及详解