码迷,mamicode.com
首页 > 其他好文 > 详细

CSU1630: Plane Ticket Pricing

时间:2015-05-25 14:36:21      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:csu

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



题意:飞机有n个座位,还有w天出发,然后给出w+1行代表每天票价定位与相应的票价所卖出的票的数量,问最多获得的价值与一开始的定价是多少

思路:首先我们要确定,每一天都是要定一个票价的,所以是一个从上而下的选择过程,然后再看相应的票价对应的座位状况,我们不仅要用dp记录最大的收益,还要记录路径

#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-8

int 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

标签:csu

原文地址:http://blog.csdn.net/libin56842/article/details/45968885

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!