• UVALive 6867 Plane Ticket Pricing


    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周了

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 int dp[301][60],n,w,sels,ans;
     4 vector<int>price[60],sales[60];
     5 int dfs(int curn,int curw){
     6     if(curn <= 0 || curw < 0) return 0;
     7     if(dp[curn][curw] != -1) return dp[curn][curw];
     8     int ret = 0;
     9     for(int i = price[curw].size()-1; i >= 0; --i){
    10         int tmp = price[curw][i]*min(curn,sales[curw][i]) + dfs(curn - min(curn,sales[curw][i]),curw+1);
    11         if(curw == 0 && tmp > ret) ans = price[curw][i];
    12         else if(curw == 0 && tmp == ret) ans = min(ans,price[curw][i]);
    13         ret = max(ret,tmp);
    14     }
    15     return dp[curn][curw] = ret;
    16 }
    17 int main() {
    18     while(~scanf("%d %d",&n,&w)) {
    19         memset(dp,-1,sizeof dp);
    20         for(int i = 0; i < 60; ++i) {
    21             price[i].clear();
    22             sales[i].clear();
    23         }
    24         for(int i = 0,tmp; i <= w; ++i) {
    25             scanf("%d",&sels);
    26             for(int j = 0; j < sels; ++j) {
    27                 scanf("%d",&tmp);
    28                 price[i].push_back(tmp);
    29             }
    30             for(int j = 0; j < sels; ++j) {
    31                 scanf("%d",&tmp);
    32                 sales[i].push_back(tmp);
    33             }
    34         }
    35         ans = 0x3f3f3f3f;
    36         printf("%d
    ",dfs(n,0));
    37         printf("%d
    ",ans);
    38     }
    39     return 0;
    40 }
    41 /*
    42 100 3
    43 4 195 223 439 852 92 63 15 1
    44 2 811 893 76 27
    45 1 638 3
    46 1 940 38
    47 */
    View Code
  • 相关阅读:
    微软开发中心的rss历史记录(22)
    asp.net dll 动态生成和调用(转)
    准备写博了
    来博客园报道啦
    web爬行器的准备工作
    跨浏览器设置标签样式
    感谢我身边的朋友们
    难过的一天:(
    12月:期待好运来
    11月 难过一整个世界都寂寞
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4529838.html
Copyright © 2020-2023  润新知