zoukankan      html  css  js  c++  java
  • 幸福的通道-洛谷4308

    传送门

    真的不好想到啊

    刚看完题目的我

    一脸懵

    做法:

      倍增+Floyd

    #include<cstdio>
    #include<algorithm>
    #include<cstring> 
    #include<iostream>
    using namespace std;
    
    inline int read()//快读 
    {
        int sum = 0,p = 1;
        char ch = getchar();
        while(ch < '0' || ch > '9')
        {
            if(ch == '-')
                p = -1;
            ch = getchar();
        }
        while(ch >= '0' && ch <= '9')
        {
            (sum *= 10)+= ch - '0';
            ch = getchar();
        }
        return sum * p;
    }
    
    #define lb long double
    const int maxn = 150;
    const lb inf = 1e30;
    int n,m,s;
    lb f[maxn][maxn],g[maxn][maxn],p,a[maxn],ans;
    
    int main()
    {
        n = read(),m = read();
        for(int i = 1;i <= n;i++)
            cin>>a[i];
        s = read();
        cin>>p;
        int x,y;
        for(int i = 0;i <= n;i++)
            for(int j = 0;j <= n;j++)
                f[i][j] = -inf;
        for(int i = 1;i <= n;i++)
            f[i][i] = 0;
        for(int i = 1;i <= m;i++)
        {
            x = read(),y = read();
            f[x][y] = a[y] * p; 
        }
        for(lb tmp = p;tmp > (lb)(1e-8);tmp *= tmp)
        {
            for(int i = 1;i <= n;i++)
                for(int j = 1;j <= n;j++)
                    g[i][j] = -inf;
            for(int k = 1;k <= n;k++)
                for(int i = 1;i <= n;i++)
                    for(int j = 1;j <= n;j++)
                        g[i][j] = max(g[i][j],f[i][k] + f[k][j] * tmp);
            memcpy(f,g,sizeof(g));
        }
        for(int i = 1;i <= n;i++)
            ans = max(ans,f[s][i]);
        printf("%.1Lf",ans + a[s]);
        return 0;
    }
  • 相关阅读:
    【BZOJ】2729: [HNOI2012]排队
    【BZOJ】2734: [HNOI2012]集合选数
    【BZOJ】3573: [Hnoi2014]米特运输
    【BZOJ】4008: [HNOI2015]亚瑟王
    【BZOJ】[HNOI2015]菜肴制作
    数论六·模线性方程组
    数论五·欧拉函数
    黄金矿工
    数论四·扩展欧几里德
    数论三·约瑟夫问题
  • 原文地址:https://www.cnblogs.com/darlingroot/p/10667418.html
Copyright © 2011-2022 走看看