zoj 3634 Bounty hunter(dp,没完全想清楚,需要回头再看_20151027)

M - Bounty hunter

Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Submit Status

Description

Bounty hunter is a hero who always moves along cities to earn money by his power. One day he decides to N cities one by one

At the beginning ,Bounty hunter has X money and Y points of Attack force. At day 1, he will goes to city 1, then city 2 at day 2, city 3 at day 3, ... At last ,he goes to city N at day N and leaves it at day N+1. In each city, he can increase his attack force by money and earn some money by accepting a task. In the city i, it costs him ai money to increase one point of attack force. And he can gets bi*yi money after finishing the task in city i while yi is his attack force after his increasing at city i.

As it‘s known to all that money is the life of Bounty hunter, he wants to own as much money as he can after leaving city N. Please find out the maximal moeny he can get.

PS1: when Bounty hunter leaves a city he won‘t come back.

PS2: Bounty hunter can increases his attack force by any real numbers he wants, if the money is enough. For example, if he has 7 money and the unit price of attack force at the city he stays now is 2, he can spend 3 money to increase attack force by 1.5.

PS3: After Bounty hunter finishes the task he will leave the city at once. It means he can and only can increase his attack force before he finishes the task and gets the money at the same city.

Input

The first line of the input is three integers N,X,Y, (0≤N,X,Y≤100000) following is N lines. In the i-th line has two real number ai and bi.(0≤bi≤1,0<ai≤100000)

Output

Output the maximal money he can get.Two decimal places reserved. We promise that the answer is less than 1e15

Sample Input

1 10 0
1.0 1.0

3 13 5
7.0 1.0
1.1 0.6
1.0 0.6

Sample Output

10.00
25.64

dp苦手。。。。看了很多题解。。。然而都是一个样。。。抄别人题解也不加个出处。。。好像是自己写的似的。。。真是无聊。。。转移方程有一个地方没想明白。。。就是dp_m[i+1]*b[i]这个式子。。。。表示啥。。。妈蛋。。。。改天再想。

 1 /*************************************************************************
 2     > File Name: code/zoj/3634.cpp
 3     > Author: 111qqz
 4     > Email: [email protected]
 5     > Created Time: 2015年10月27日 星期二 13时46分35秒
 6  ************************************************************************/
 7
 8 #include<iostream>
 9 #include<iomanip>
10 #include<cstdio>
11 #include<algorithm>
12 #include<cmath>
13 #include<cstring>
14 #include<string>
15 #include<map>
16 #include<set>
17 #include<queue>
18 #include<vector>
19 #include<stack>
20 #include<cctype>
21
22 #define yn hez111qqz
23 #define j1 cute111qqz
24 #define ms(a,x) memset(a,x,sizeof(a))
25 using namespace std;
26 const int dx4[4]={1,0,0,-1};
27 const int dy4[4]={0,-1,1,0};
28 typedef long long LL;
29 typedef double DB;
30 const int inf = 0x3f3f3f3f;
31 const int N=1E5+7;
32 double a[N],b[N],dp_a[N],dp_m[N];
33 int n;
34 int x,y;
35 int main()
36 {
37   #ifndef  ONLINE_JUDGE
38    freopen("in.txt","r",stdin);
39   #endif
40
41    while (scanf("%d %d %d",&n,&x,&y)!=EOF)
42     {
43     for ( int i = 1 ; i <= n ; i++) scanf("%lf %lf",&a[i],&b[i]);
44
45     ms(dp_a,0);
46     ms(dp_m,0);
47     dp_a[n] = b[n];
48     dp_m[n] =max(1.0,1.0/a[n]*b[n]);
49
50     for ( int  i = n-1 ; i >=1 ; i--)
51     {
52         dp_a[i] = dp_m[i+1]*b[i]+dp_a[i+1];        //转移方程还是没太想清楚TAT  主要是dp_m[i+1]*b[i]这部分。。。再想一下
53         dp_m[i] = max(dp_m[i+1],1.0/a[i]*dp_a[i]);
54     }
55     printf("%.2f\n",x*dp_m[1]+y*dp_a[1]);
56     }
57
58
59  #ifndef ONLINE_JUDGE
60   fclose(stdin);
61   #endif
62     return 0;
63 }

时间: 2024-08-05 06:31:17

zoj 3634 Bounty hunter(dp,没完全想清楚,需要回头再看_20151027)的相关文章

CSU 1527 Bounty Hunter dp 双调旅行商

题目链接:点击打开链接 裸的双调旅行商问题啦 #include <stdio.h> #include <string.h> #include <iostream> #include <math.h> #include <queue> #include <set> #include <algorithm> #include <stdlib.h> using namespace std; #define ll in

CodeForcesGym 100753B Bounty Hunter II

Bounty Hunter II Time Limit: 5000ms Memory Limit: 262144KB This problem will be judged on CodeForcesGym. Original ID: 100753B64-bit integer IO format: %I64d      Java class name: (Any) 解题:最小路径覆盖 1 #include <bits/stdc++.h> 2 using namespace std; 3 co

exam1802 Bounty Hunter II(DAG的最小路径覆盖)

原文:http://www.cnblogs.com/jackiesteed/articles/2043934.html DAG的最小路径覆盖是指找最小数目的互相不相交的有向路径,满足DAG的所有顶点都被覆盖. 首先给出公式:DAG的最小路径覆盖数=DAG图中的节点数-相应二分图中的最大匹配数. 那么对应一个DAG,如何构造相应的二分图?对于DAG中的一个顶点p,二分图中有两个顶点p和p',对应DAG中的一条有向边p->q,二分图中有p-q'的一条无向边.二分图中p属于S集合,p'属于T集合. 下

在美国当个程序员,没你想的那么难

想在美国当程序员?可能没你想象的那么难.就算没钱去正经大学念个计算机科学,也有其他出路. 最近,越来越多的在线学习编程学校在美国火了起来.许多真实的案例都为一些有志于此的人指出了一条光明大道:无论你是想找工作的穷学生,还是想改行的中年危机男,程序员的世界都欢迎你. "闪电战"编程课程 西雅图的"代码伙伴"(Code Fellows)学校,就非常确信他们能够帮助学生找到工作.他们为学生提供六个星期的"闪电战"编程课程,让学生能够完成从零基础达到基本

线程池没你想的那么简单(续)

前言 前段时间写过一篇<线程池没你想的那么简单>,和大家一起撸了一个基本的线程池,具备: 线程池基本调度功能. 线程池自动扩容缩容. 队列缓存线程. 关闭线程池. 这些功能,最后也留下了三个待实现的 features . 执行带有返回值的线程. 异常处理怎么办? 所有任务执行完怎么通知我? 这次就实现这三个特性来看看 j.u.c 中的线程池是如何实现这些需求的. 再看本文之前,强烈建议先查看上文<线程池没你想的那么简单> 任务完成后的通知 大家在用线程池的时候或多或少都会有这样的需

Java程序员面试体会,还没找到工作的“猿猿们”看过来!

类似的话题,我大约在几个月前跟大家聊过.这一次,我要根据这段时间的体会,再给大家整理一下. 今天,很轻松地拿到了神州数码的offer.虽然工资不是特别高,虽然很多人一毕业就能进入这样的公司,但是对我这个半路出家的大专生来说,能进去纯属意外. 今天的面试,谈到了以前我接过一些私单,项目经理问我,那你现在还有没有做私活的想法?我说,彻底没有!他问我,为什么?我说,这几年,虽然做私活挣了一些钱,但我损失的远远不止那点钱.那些重复.繁琐,很难有技术水平提升的工作,占用了我大部份的业余时间,如果这些时间用

《windows程序设计》第一章,建议想学API的每天看一章

开始 壹佰软件开发小组  整理编译   本书介绍了在Microsoft Windows 98.Microsoft Windows NT 4.0和Windows NT 5.0下程序写作的方法.这些程序用C语言编写并使用原始的Windows Application Programming Interface(API).如在本章稍后所讨论的,这不是写作Windows程序的唯一方法.然而,无论最终您使用什么方式写作程序,了解Windows API都是非常重要的. 正如您可能知道的,Windows 98已

poj3687 拓扑排序 还没怎么搞明白 回头再想想

[题意]:n个重量为1~n的球,给定一些球之间的重量比较关系(如 2 1  表示第二个球比第一个球轻),求每个球可能的重量,ans[i] 表示第i个球的重量,要求输出的是ans字典序最小的情况. [思路]:对于给出的a b  建反边,每次 在出度为0的所有点里选一个序号最小的赋值(从n开始 由大到小赋). 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<string>

[ACM] ZOJ 3725 Painting Storages (DP计数+组合)

Painting Storages Time Limit: 2 Seconds      Memory Limit: 65536 KB There is a straight highway with N storages alongside it labeled by 1,2,3,...,N. Bob asks you to paint all storages with two colors: red and blue. Each storage will be painted with e