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 }