Light OJ 1342 - Aladdin and the Magical Sticks (概率DP)
来源:互联网 发布:万合星多屏软件破解版 编辑:程序博客网 时间:2024/06/05 01:05
解析:设dp[i][j]为有i个未放入的可辨别的砖块和j个未放入的不可辨别的砖块时,放入不可辨别的砖块的重量期望值。
num1,tot1分别是可辨别砖块的个数和重量和;
num2,tot2分别是不可辨别砖块的个数和重量和。
那么dp[i][j] = (num2-j)*dp[i][j]/(i+num2) + j*dp[i][j-1]/(i+num2) + i*dp[i-1][j]/(i+num2) + tot2/(i+num2);
[code]:
#include<cstdio>#include<cstring>using namespace std;const int maxn = 5005;double dp[2][maxn];int n,a[maxn],b[maxn],num1,num2,tot1,tot2;void init(){ num1 = num2 = 0; tot1 = tot2 = 0; dp[0][0] = 0;}void sol(){ int i,j,cr,pr;double ans; for(i = 0;i <= num1;i++){ cr = i&1;pr = (cr+1)&1; for(j = 0;j <= num2;j++){ if(!i&&!j) continue; ans = tot2; if(j) ans += j*dp[cr][j-1]; if(i) ans += i*dp[pr][j]; dp[cr][j] = ans/(i+j); } } printf("%.6f\n",dp[num1&1][num2]+tot1);}int main(){ int i,j,cas; scanf("%d",&cas); for(int T=1;T<=cas;T++){ scanf("%d",&n); init(); for(i = 1;i <= n;i++){ scanf("%d%d",&a[i],&b[i]); if(b[i]==1) tot1 += a[i],num1++; else tot2 += a[i],num2++; } printf("Case %d: ",T); sol(); } return 0;}
0 0
- Light OJ 1342 - Aladdin and the Magical Sticks (概率DP)
- 【概率DP】 LightOJ 1342 Aladdin and the Magical Sticks
- LightOJ-1342 Aladdin and the Magical Sticks(期望dp)
- LightOJ 1342 - Aladdin and the Magical Sticks
- [LightOJ 1342] Aladdin and the Magical Sticks (期望的线性性质+几何分布+邮票收集问题)
- Light OJ 1348 - Aladdin and the Return Journey(树链剖分)
- Light OJ Aladdin and the Flying Carpet(约数个数)
- Light OJ 1341 Aladdin and the Flying Carpet
- Light OJ 1343 - Aladdin and the Black Stones
- Light OJ 1349 Aladdin and the Optimal Invitation
- light oj 1341 Aladdin and the Flying Carpet
- Aladdin and the Flying Carpet Light OJ 1341
- Light OJ 1341 Aladdin and the Flying Carpet Pollard_rho整数分解+DFS
- Light OJ 1341 Aladdin and the Flying Carpet(唯一分解定理)
- [整数分解+dfs] light oj 1341 Aladdin and the Flying Carpet
- Light OJ 1348 Aladdin and the Return Journey 树链剖分水题
- Light OJ 1348 Aladdin and the Return Journey(树剖-点)
- Light OJ 1341 Aladdin and the Flying Carpet(算数基本定理)
- EasyUI体验-分页多选,选项保留,以及历史记录相结合的保留
- String,StringBuffer,StringBuilder之间的区别
- 方便学习的一些经典网站
- SLAM学习
- 数据平台的简单使用
- Light OJ 1342 - Aladdin and the Magical Sticks (概率DP)
- VS2013中 scanf()函数返回值
- leetcode 16: 3 Sum closest (C#版)
- sklearn.pipeline.Pipeline类的用法
- sklearn.preprocessing.PolynomialFeatures类的使用
- 2015年简短总结
- 分治法求最接近点对问题
- Java网络详解
- leetcode 59. Spiral Matrix II