题面

luogu

CodeForces

题解

\(orz\) yyb

转移蜜罐其实是吓唬人的......

转移的蜜罐都是尝试过的,所有只关心当前架子上的蜜罐数

设\(f[i][j]\)表示第i个货架有j个蜜罐没有被试吃的概率

然后枚举品尝了几个之前没有品尝过的,组合数转移一下

Code

#include<bits/stdc++.h>

#define LL long long
#define RG register using 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;
}

最新文章

  1. C#移动跨平台开发(1)环境准备
  2. Scalaz(31)- Free :自由数据结构-算式和算法的关注分离
  3. 02 key concept
  4. C#中有关string和byte[]转换的问题
  5. ACCESS的System.Data.OleDb.OleDbException: INSERT INTO 语句的语法错误
  6. (转)深入理解 __doPostBack
  7. ios 6 横竖屏转换
  8. 如何给sublime text3安装汉化包?so easy 哦
  9. 总结C语言字符检测函数:isalnum、isalpha...
  10. Elasticsearch 5.x 字段折叠的使用
  11. .NET Threadpool的一点认识
  12. Linux基础命令---lprm删除打印任务
  13. C++ QT中自定义控件的简单创建
  14. python中if else流程判断
  15. 【转载】 Caffe BN+Scale层和Pytorch BN层的对比
  16. (记忆化搜索) FatMouse and Cheese(hdu 1078)
  17. query 中 radio选中小技巧
  18. Redis:按照正则批量删除key
  19. canvas的图片绘制案例
  20. tensorflow data&#39;s save and load

热门文章

  1. vectors 使用应该注意到的问题
  2. sqlserver临时表或表变量代替游标
  3. Docker学习笔记_安装和使用Python
  4. linux ssh使用深度解析(key登录详解)
  5. Thumbnail 图片帮助
  6. hibernate的获取session的两方法比较,和通过id获取对象的比较,一级缓存二级缓存
  7. Backbone.js 0.9.2 中文解释
  8. perationalError: (2003, &quot;Can&#39;t connect to MySQL server on u&#39;192.168.1.6&#39; (timed out)&quot;)
  9. 关于CS0016: Could not write to output file ‘c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary AS
  10. Regex 常用的正则表达式