zoukankan      html  css  js  c++  java
  • Codeforces 248E Piglet's Birthday dp

    Piglet's Birthday

    dp[ i ][ j ] 表示目前位置, 第 i 个架子上的蜂蜜还有 j 个没有吃过的概率。

    j 是不会增加的, 所以复杂度是对的。 但是我感觉我计算过程中的精度不怎么行啊, 怎么也过了。。

    #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 = 998244353;
    const double eps = 1e-10;
    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;}
    
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    
    int n, q, a[N], sum[N];
    double ans, C[N][107];
    
    double dp[N][107], f[107];
    
    void addPot(int id, int k) {
        sum[id] += k;
    }
    
    void subPot(int id, int k) {
        double tmp = dp[id][0];
        memset(f, 0, sizeof(f));
        for(int i = 0; i <= 100; i++) {
            for(int j = 0; j <= k; j++) {
                f[i] += dp[id][i + j] * C[i + j][j] * C[sum[id] - i - j][k - j] / C[sum[id]][k];
            }
        }
        for(int i = 0; i <= 100; i++) {
            dp[id][i] = f[i];
        }
        ans += dp[id][0] - tmp;
        sum[id] -= k;
    }
    
    int main() {
    
        for(int i = 0; i < N; i++) {
            for(int j = C[i][0] = 1; j <= min(100, i); j++) {
                C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
            }
        }
    
        scanf("%d", &n);
    
        for(int i = 1; i <= n; i++) {
            scanf("%d", &a[i]);
            sum[i] = a[i];
            dp[i][a[i]] = 1;
            ans += dp[i][0];
        }
    
        scanf("%d", &q);
    
        while(q--) {
    
            int u, v, k;
            scanf("%d%d%d", &u, &v, &k);
    
            subPot(u, k);
            addPot(v, k);
    
            printf("%.12f
    ", ans);
        }
        return 0;
    }
    
    /*
    */
  • 相关阅读:
    华为Mate8 NFC 时好时坏,怎么解决呢?
    linux下使用FreeRDP 连接 Windows 远程桌面
    Linux下如何查看系统启动时间和运行时间以及安装时间
    运维监控系统之Open-Falcon
    gitlab之邮箱配置
    Ubuntu系统日志
    安装docker-compose的两种方式
    Linux用户配置sudo权限(visudo)
    Centos7下部署两套python版本并存
    线上mongodb 数据库用户到期时间修改的操作记录
  • 原文地址:https://www.cnblogs.com/CJLHY/p/11120105.html
Copyright © 2011-2022 走看看