zoukankan      html  css  js  c++  java
  • Eating Everything Efficiently

    问题 E: Eating Everything Efficiently

    时间限制: 1 Sec  内存限制: 128 MB  Special Judge
    提交: 60  解决: 5
    [提交] [状态] [命题人:admin]

    题目描述

    Margriet A. is in pizza heaven! She has bought a one-day access pass to Pizza World. Pizza World is a food festival, where all stands have their own special type of pizza. Margriet would really like to try many different types of pizza, but she thinks that she can only eat two pizzas in total. Therefore, she has come up with a cunning plan: at each stall she visits she decides whether she wants to buy this pizza or not. At the first stall where she decides to make a purchase, she will buy and eat exactly one pizza.
    At the second one, she will buy and eat half a pizza, and at the third she will eat one quarter of a pizza, etc.. Therefore, at the kth stall where she decides to buy some pizza, she will eat  part of a pizza. This way she makes sure that she will never get full!
    In order to ensure that the flow of people in the park is adequate, the pizza stalls are connected by one-way paths, and to make sure that everyone will leave the festival, it is made impossible to visit a pizza stall more than once. However, every stall can be reached from the stall at the entrance, which is the stall with number 0. 
    Of course, Margriet has her own taste: she will like some pizzas more than others. Eating pizza from a stall will give her a certain amount of satisfaction which is equal to Margriet’s personal stall satisfaction number multiplied by the fraction of a whole pizza she eats there.
    Her total satisfaction is the sum of satisfactions of every stall she visits. Can you help Margriet plot a route between the pizza stalls that satisfies her the most?

    输入

    • Two integers 1 ≤ n ≤ 5 · 105 and 0 ≤ m ≤ 5 · 105, the number of pizza stalls and the number of one way connections.
    • The second line has n integers c0, . . . , cn−1, 0 ≤ ci ≤ 109, the amount of enjoyment Margriet gets from eating one pizza at stall i.
    • The next m lines each contain 2 integers 0 ≤ s < n and 0 ≤ t < n, ndicating a one way path from stall s to stall t. No connection will appear twice in the input.

    输出

    Print the maximal amount of enjoyment Margriet can reach at the pizza fair. Your answer will be considered correct if it differs from the actual answer by at most 10−6 absolutely or relatively.

    样例输入

    5 5
    1 4 6 2 100
    0 1
    1 2
    0 3
    2 4
    3 4
    

    样例输出

    100
    #pragma GCC optimize(3,"Ofast","inline")
    #include <bits/stdc++.h>
    
    using namespace std;
    typedef long long ll;
    const int maxn = 5e5 + 10;
    const int N=28;
    struct node{
        int to,nx;
    }o[maxn];
    int n,m;
    int head[maxn],val[maxn],tot,vis[maxn];
    double pre[N+1],dp[maxn][N+1];
    inline void add_edge(int u,int v){
        o[++tot].to=v;
        o[tot].nx=head[u];
        head[u]=tot;
    }
    inline void solve(int cur){
        if(vis[cur])return;
        vis[cur]=1;
        dp[cur][0]=0,dp[cur][1]=val[cur];
        for(register int i=head[cur];i;i=o[i].nx){
            int to=o[i].to;
            solve(to);
            for(register int j=1;j<27;++j){
                if(dp[to][j-1]!=-1){
                    dp[cur][j]=max(dp[cur][j],dp[to][j-1]+val[cur]*pre[j-1]);
                }
                if(dp[to][j]!=-1){
                    dp[cur][j]=max(dp[cur][j],dp[to][j]);
                }
            }
        }
    }
    int main() {
        //freopen("1.txt","r",stdin);
        pre[0]=1;
        for(register int i=1;i<N;++i){
            pre[i]=pre[i-1]/2.0;
            //printf("pre[%d] = %.10f
    ",i,pre[i]);
        }
        scanf("%d%d",&n,&m);
        for(register int i=0;i<=n;++i){
            for(register int j=0;j<=28;++j){
                dp[i][j]=1;
            }
        }
        for(register int i=1;i<=n;++i)scanf("%d",&val[i]);
        for(register int i=1,u,v;i<=m;++i){
            scanf("%d%d",&u,&v);
            ++u,++v;
            add_edge(v,u);
        }
        for(register int i=1;i<=n;++i){
            if(!vis[i])solve(i);
        }
        double res=0;
        for(register int i=1;i<=n;++i){
            for(register int j=0;j<27;++j){
                res=max(res,dp[i][j]);
            }
        }
        printf("%.10f
    ",res);
        return 0;
    }
     
  • 相关阅读:
    PAT 顶级 1010 Lehmer Code (35 分)
    PAT 顶级 1010 Lehmer Code (35 分)
    CCF CSP 201909-4 推荐系统
    CCF CSP 201909-4 推荐系统
    Codeforces 1251C Minimize The Integer
    Codeforces 1251C Minimize The Integer
    CCF CSP 201803-4 棋局评估
    CCF CSP 201803-4 棋局评估
    【DP_树形DP专题】题单总结
    【DP_树形DP专题】题单总结
  • 原文地址:https://www.cnblogs.com/czy-power/p/11420595.html
Copyright © 2011-2022 走看看