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. spark scala word2vec 和多层分类感知器在情感分析中的实际应用

    转自:http://www.cnblogs.com/canyangfeixue/p/7227998.html 对于威胁检测算法使用神经网络训练有用!!!TODO待实验 /** * Created by ...

  2. hdoj--1005--Number Sequence(规律题)

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. Spring Boot: Tuning your Undertow application for throughput--转

    原文地址:https://jmnarloch.wordpress.com/2016/04/26/spring-boot-tuning-your-undertow-application-for-thr ...

  4. <Sicily>Polynomial

    一.题目描述 Given a polynomial and the value of the variable x, you task is to calculate the value of the ...

  5. css hover图片hover效果兼容ie8

    例子: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...

  6. hdu 3292 No more tricks, Mr Nanguo

    No more tricks, Mr Nanguo Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Jav ...

  7. oracle创建静态监听

    [oracle@localhost admin]$ pwd /u01/app/oracle/product/11.2.0/dbhome_1/network/admin [oracle@localhos ...

  8. sed命令的介绍

    命令格式 sed [options] 'command' file(s) sed [options] -f scriptfile file(s) 选项 -e<script>或--expre ...

  9. 【IDEA】Error: java: Compliance level '1.6' is incompatible with target level '1.8'. A compliance level '1.8' or better is required解决办法

    在运行的时候常常出现如下错误: Error: java: Compliance level '1.6' is incompatible with target level '1.8'. A compl ...

  10. 最长回文字串 (The longest palindrome substring)

    这两天去学了一下,觉得下面那篇文章写的很好,有例子,比较容易懂,所以转一下. 以下内容来自:hihoCoder: 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互 ...