题目: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. 《30天学习30种新技术》-Day 15:Meteor —— 从零开始创建一个 Web 应用

    目录:https://segmentfault.com/a/1190000000349384 原文: https://segmentfault.com/a/1190000000361440 到目前为止 ...

  2. 二叉树遍历 Morris

    二叉树的遍历,先根遍历,不适用递归,存储空间为 O(1) 转自:http://chuansongme.com/n/100461 MorrisInOrder(): while 没有结束 如果当前节点没有 ...

  3. AC日记——线段树练习三 codevs 1082 (分块尝试)

    线段树练习 3 思路: 分块: 来,上代码: #include <cmath> #include <cstdio> #include <cstring> #incl ...

  4. WKWebView遇到的问题汇总

    一.手势放大缩小页面解决方法 1.通过操作webview中scrollview的代理方法来关闭 -(UIView *)viewForZoomingInScrollView:(UIScrollView ...

  5. 微信小程序 图片路径自动加上文件目录导致渲染报错问题

    最近 在做小程序时候,发现一些商品图片在渲染时一直报错,也不显示,但是控制台打印出来 的路径却有没有问题 报错提示出错的路径会在前面自动加上“page/**”,思索了之后想到了微信只能解释https的 ...

  6. Codeforces 703D Mishka and Interesting sum(离线 + 树状数组)

    题目链接  Mishka and Interesting sum 题意  给定一个数列和$q$个询问,每次询问区间$[l, r]$中出现次数为偶数的所有数的异或和. 设区间$[l, r]$的异或和为$ ...

  7. Codeforces 777D Cloud of Hashtags(贪心)

    题目链接 Cloud of Hashtags 题目还是比较简单的,直接贪心,但是因为我有两个细节没注意,所以FST了: 1.用了cin读入,但是没有加 std::ios::sync_with_stdi ...

  8. 基于Java实现的选择排序算法

    选择排序和冒泡排序同样是基础排序算法,现在也做个学习积累. 简述 选择排序算法较为稳定,基本上都是O(n2)的时间复杂度,规模越小排序越快,不需要占用额外空间.其实选择排序原理很简单,就是在未排序序列 ...

  9. Python学习笔记——安装

    最近打算使用下GAE,便准备学习一下python.我对python是一窍不通,因此这里将我的学习历程记录下来,方便后续复习. 安装python: 可以从如下地址:http://www.python.o ...

  10. 聊聊、Zookeeper Linux 集群服务

    今天是平安夜,先祝大家平安夜快乐.这篇文章我们来谈谈 Zookeeper Linux 集群. 为什么要集群呢?因为一台服务不够.集群是为了系统扩容,系统稳定.一台服务挂了,没关系,我还有其他的服务.集 ...