zoukankan      html  css  js  c++  java
  • zoj 3634 Bounty hunter(dp,已经想明白)

    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]这个式子。。。。表示啥。。。
    妈蛋。。。。改天再想。
    update_2015_10_27晚上:
    傻逼了。。。dpa[i]和dp[m]表示的都是能赚到的最多钱数。。。dpa[i]表示的不是攻击力!!!
    上午看怎么dp_m[i+1]*b[i]表示的应该是第i天能赚到的钱数(的一部分)。。怎么加给攻击力了orz....脑袋真是补清醒的可以。。。。。
    想清楚就没问题了。
     1 /*************************************************************************
     2     > File Name: code/zoj/3634.cpp
     3     > Author: 111qqz
     4     > Email: rkz2013@126.com 
     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
    ",x*dp_m[1]+y*dp_a[1]);
    56     }
    57   
    58    
    59  #ifndef ONLINE_JUDGE  
    60   fclose(stdin);
    61   #endif
    62     return 0;
    63 }
    View Code
  • 相关阅读:
    两个链表的第一个公共节点(Python and C++解法)
    第一个只出现一次的字符(Python and C++解法)
    丑数(Python and C++解法)
    最长不含重复字符的子字符串(Python and C++解法)
    礼物的最大值(Python and C++解法)
    把数字翻译成字符串(Python and C++解法)
    连续子数组的最大和(Python and C++解法)
    最小的k个数(Python and C++解法)
    数组中出现次数超过一半的数字(Python and C++解法)
    字符串的排列(Python and C++解法)
  • 原文地址:https://www.cnblogs.com/111qqz/p/4914027.html
Copyright © 2011-2022 走看看