日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CF248E Piglet's Birthday(概率dp)

發布時間:2025/3/15 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CF248E Piglet's Birthday(概率dp) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題面

luogu
CodeForces

題解

\(orz\) yyb

轉移蜜罐其實是嚇唬人的......
轉移的蜜罐都是嘗試過的,所有只關心當前架子上的蜜罐數

\(f[i][j]\)表示第i個貨架有j個蜜罐沒有被試吃的概率
然后枚舉品嘗了幾個之前沒有品嘗過的,組合數轉移一下

Code

#include<bits/stdc++.h>#define LL long long #define RG registerusing namespace std; template<class T> inline void read(T &x) {x = 0; RG char c = getchar(); bool f = 0;while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') c = getchar(), f = 1;while (c >= '0' && c <= '9') x = x*10+c-48, c = getchar();x = f ? -x : x;return ; } template<class T> inline void write(T x) {if (!x) {putchar(48);return ;}if (x < 0) x = -x, putchar('-');int len = -1, z[20]; while (x > 0) z[++len] = x%10, x /= 10;for (RG int i = len; i >= 0; i--) putchar(z[i]+48);return ; } const int N = 100010; int a[N], b[N]; double f[N][110];inline LL C(int n, int m) {if (n < m) return 0;LL s = 1;for (int i = n; i > n-m; i--) s *= i;for (int i = m; i > 1; i--) s /= i;return s; }int main() {//freopen(".in", "r", stdin);//freopen(".out", "w", stdout);int n, q; read(n);for (int i = 1; i <= n; i++) read(a[i]), b[i] = a[i];double ans = 0;for (int i = 1; i <= n; i++) f[i][a[i]] = 1;for (int i = 1; i <= n; i++) ans += f[i][0];read(q);while (q--) {int u, v, K; read(u); read(v); read(K);ans -= f[u][0];for (int i = 0; i <= a[u]; i++) {double g = 0;LL t = C(b[u], K);for (int k = 0; k <= K; k++) g += f[u][i+k]*C(i+k, k)*C(b[u]-i-k, K-k)*1.0/t;f[u][i] = g;}b[u] -= K; b[v] += K;ans += f[u][0];printf("%.10lf\n", ans);}return 0; }

轉載于:https://www.cnblogs.com/zzy2005/p/10220190.html

總結

以上是生活随笔為你收集整理的CF248E Piglet's Birthday(概率dp)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。