题目:http://community.topcoder.com/stat?c=problem_statement&pm=13239&rd=15859

用到了概率论中的贝叶斯公式,而贝叶斯公式中须要用到的概率须要用dp方法求解。

代码:

#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <iostream>
#include <sstream>
#include <iomanip> #include <bitset>
#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map> #include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std; #define CHECKTIME() printf("%.2lf\n", (double)clock() / CLOCKS_PER_SEC)
typedef pair<int, int> pii;
typedef long long llong;
typedef pair<llong, llong> pll;
#define mkp make_pair /*************** Program Begin **********************/
const int MAX_SCORE = 50 * 50;
class FixedDiceGameDiv1 {
public:
double dp1[MAX_SCORE + 1], dp2[MAX_SCORE + 1]; // dp[i]: roll a b-sieded dice 最后总得分为i的概率
void calc(int a, int b, double dp[])
{
for (int i = 0; i < MAX_SCORE + 1; i++) {
dp[i] = 0.0;
}
dp[0] = 1.0;
for (int i = 0; i < a; i++) {
for (int j = a * b; j >= 0; j--) {
if (dp[j] == 0) {
continue;
}
for (int k = 1; k <= b; k++) {
dp[j + k] += dp[j] / b;
}
dp[j] = 0;
}
}
}
double getExpectation(int a, int b, int c, int d) {
double res = 0.0; calc(a, b, dp1);
calc(c, d, dp2); // 贝叶斯公式
double up = 0, down = 0;
for (int i = a; i <= a * b; i++) {
for (int j = 0; j < i; j++) {
up += dp1[i] * dp2[j] * i;
down += dp1[i] * dp2[j];
}
} if (down == 0) {
return -1;
}
res = up / down; return res;
} }; /************** Program End ************************/

SRM 626 D1L1: FixedDiceGameDiv1,贝叶斯公式,dp的更多相关文章

  1. SRM 510 2 250TheAlmostLuckyNumbersDivTwo(数位dp)

    SRM 510 2 250TheAlmostLuckyNumbersDivTwo Problem Statement John and Brus believe that the digits 4 a ...

  2. Topcoder SRM 698 Div1 250 RepeatString(dp)

    题意 [题目链接]这怎么发链接啊..... Sol 枚举一个断点,然后类似于LIS一样dp一波 这个边界条件有点迷啊..fst了两遍... #include<bits/stdc++.h> ...

  3. Topcoder SRM 626 DIV2 SumOfPower

    本题就是求所有连续子数列的和 开始拿到题目还以为求的时数列子集的和,认真看到题目才知道是连续子数列 循环遍历即可 int findSum(vector <int> array) { ; ; ...

  4. Topcoder SRM 626 DIV2 FixedDiceGameDiv2

    典型的条件概率题目. 事件A在另外一个事件B已经发生条件下的发生概率.条件概率表示为P(A|B),读作“在B条件下A的概率”. 若只有两个事件A,B,那么, P(A|B)=P(AB)/P(B) 本题的 ...

  5. TC250专场

    SRM 623 DIV2 1000pt 题意:给出一个最多50*50的矩阵,每个单元可能为'.'.'P'.'A','.'代表空地,你每次操作可以把一个P或者A拿到空地上,求一个最大的含有相同字符的矩形 ...

  6. ATC/TC/CF

    10.25 去打 CF,然后被 CF 打了. CF EDU 75 A. Broken Keyboard 精神恍惚,WA 了一发. B. Binary Palindromes 比赛中的憨憨做法,考虑一个 ...

  7. SRM 628 D1L3:DoraemonPuzzleGame,math,后市展望,dp

    称号:c=problem_statement&pm=13283&rd=16009">http://community.topcoder.com/stat?c=probl ...

  8. SRM 620 D2L3: RandomGraph, dp

    称号:http://community.topcoder.com/stat? c=problem_statement&pm=13143&rd=15853 參考:http://apps. ...

  9. SRM DIV1 500pt DP

    SRM 501 DIV1 500pt SRM 502 DIV1 500pt SRM 508 DIV1 500pt SRM 509 DIV1 500pt SRM 511 DIV1 500pt SRM 5 ...

随机推荐

  1. Oracle 表分区partition(http://love-flying-snow.iteye.com/blog/573303)

    http://www.jb51.net/article/44959.htm Oracle表分区分为四种:范围分区,散列分区,列表分区和复合分区. 一:范围分区 就是根据数据库表中某一字段的值的范围来划 ...

  2. Codeforces 766E Mahmoud and a xor trip(树形DP)

    题目链接 Mahmoud and a xor trip 树形DP.先考虑每个点到他本身的距离和,再算所有点两两距离和. 做的时候考虑二进制拆位即可. #include <bits/stdc++. ...

  3. bzoj 4465: [Jsoi2013]游戏中的学问

    4465: [Jsoi2013]游戏中的学问 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 121  Solved: 59[Submit][Statu ...

  4. 学习GRPC(一) 简单实现

    Grpc 实现流程图 资料 https://grpc.io/docs/quickstart/go/ https://studygolang.com/articles/16627 使用方法 make r ...

  5. 在网页里插入flash的代码

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://down ...

  6. hdu4493(C++)

    //卡格式的题目 #include<iostream> #include<iomanip>using namespace std;int main(){ int T,i; do ...

  7. Linux系统救援模式应用:恢复误删的系统文件

    利用Linux系统救援模式找回误删的系统文件 背景:在操作中误删了某些重要的系统文件如/lib64/libc.so.6这个文件,可以利用Linux系统的救援模式来找回 步骤: 将系统光盘或U盘在Bio ...

  8. 2016.6.21 maven:Failure to transfer ... from ....

    问题描述: 才刚新建的工程,什么都没做,就显示pom.xml有问题,在第一行的标签上 有如下错误: 点击详情: Failure to transfer org.apache.maven:maven-p ...

  9. 【React Native开发】React Native移植原生Android项目(4)

    ),React Native技术交流4群(458982758),请不要反复加群!欢迎各位大牛,React Native技术爱好者加入交流!同一时候博客左側欢迎微信扫描关注订阅号,移动技术干货,精彩文章 ...

  10. HTTP错误状态码定位与解决

    实践总结 本次基于对500错误定位为例,给大家讲解整个分析过程与解决方法. 1.本次实践为HTTP错误状态码定位提供一个高效.精确的定位方式,不仅仅局限于500错误. 2.针对500错误本身,可以基于 ...