zoukankan      html  css  js  c++  java
  • Codeforces 464D World of Darkraft

    World of Darkraft - 2

    每个武器可以独立考虑贡献, 我们算单个武器的贡献。

    考虑最朴素的dp, dp[ i ][ j ] 表示当前还有 i 个怪没有打, 当前的武器等级是 j 最后获得硬币的期望。

    这显然是个n ^ 2的dp, 但是通过观察我们能发现, j 达到很大的概率非常小, 因为有在[1 - t + 1] 随机取一个只有 1 / (t + 1)的概率变大。

    所以 j 这维经过测试开600就可以了, 然后我们就能很愉快地滚动dp了。

    #include<bits/stdc++.h>
    #define LL long long
    #define LD long double
    #define ull unsigned long long
    #define fi first
    #define se second
    #define mk make_pair
    #define PLL pair<LL, LL>
    #define PLI pair<LL, int>
    #define PII pair<int, int>
    #define SZ(x) ((int)x.size())
    #define ALL(x) (x).begin(), (x).end()
    #define fio ios::sync_with_stdio(false); cin.tie(0);
    
    using namespace std;
    
    const int N = 1e5 + 7;
    const int inf = 0x3f3f3f3f;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const int mod = 1e9 + 7;
    const double eps = 1e-8;
    const double PI = acos(-1);
    
    template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;}
    template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < 0) a += mod;}
    template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;}
    template<class T, class S> inline bool chkmin(T& a, S b) {return a > b ? a = b, true : false;}
    
    int n, k;
    double dp[2][602];
    double* f = dp[0];
    double* g = dp[1];
    
    int main() {
        scanf("%d%d", &n, &k);
        for(int i = n - 1; i >= 0; i--) {
            swap(f, g);
            for(int j = 1; j <= min(n + 1, 600); j++) {
                f[j] = 0;
                f[j] += 1.0 * (k - 1) / k * g[j];
                f[j] += (1.0 / k) * (1.0 / (j + 1)) * (j + g[j + 1]);
                f[j] += (1.0 / k) * (1.0 / (j + 1)) * (((1 + j) * j / 2) + j * g[j]);
            }
        }
        printf("%.12f
    ", k * f[1]);
        return 0;
    }
    
    /*
    */
  • 相关阅读:
    redis使用
    ZooKeeper之service discovery
    Git环境配置
    Windows 下MySql Replication(复制)配置
    Django框架简介(MVC框架和MTV框架)
    ftp连接服务器失败||或者Xshell链接错误:Could notconnect to '192.168.18.128' (port 22): Connection failed
    git
    roles
    ansible 中的模块
    ansible 中的 playbook 模块
  • 原文地址:https://www.cnblogs.com/CJLHY/p/10834073.html
Copyright © 2011-2022 走看看