题目: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. 通过Java实现斗地主

    功能:洗牌,发牌,对玩家手中的牌排序,看牌 package demo06; import java.util.ArrayList; import java.util.Collections; impo ...

  2. hdu1465 动态规划

    题目 一个人写了n封不同的信及相应的n个不同的信封,他把这n封信都装错了信封,问都装错信封的装法有多少种? 解体思路 用A.B.C--表示写着n位友人名字的信封,a.b.c--表示n份相应的写好的信纸 ...

  3. FZU 1057 a^b 【数论/九余定理】

    Accept: 1164    Submit: 3722Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem Description 对于任 ...

  4. shell实现自动备份整个数据库,一个库备份一个文件

    自动实现备份整个数据库 实现一个库备份一个文件 实现排除不需要备份的库 实现备份成压缩文件 实现定义保留多少天的备份文件 核心代码 #!/bin/bash #set -x ############## ...

  5. SecureCRT介绍、安装、使用(转)

    http://blog.csdn.net/liang19890820/article/details/49701429 简介 SecureCRT是一款支持SSH(SSH1和SSH2)的终端仿真程序,简 ...

  6. 清理Xcode的技巧和方法

    移除对旧设备的支持 影响:可重新生成:再连接旧设备调试时,会重新自动生成.我移除了4.3.2, 5.0, 5.1等版本的设备支持. 路径:~/Library/Developer/Xcode/iOS D ...

  7. SVN的Status字段含义

    执行SVN up和svn merge等命令出现在首位置的各字母含义如下: “ ” 无修改 “A” 新增 “C” 冲突 “D” 删除 “G” 合并 “I” 忽略 “M” 改变 “R” 替换 “X” 未纳 ...

  8. metasploit study

    load db_trackerdb_nmap -T Aggressive -sV -n -O -v 192.168.0.107 绑定shelluse exploit/windows/smb/ms08_ ...

  9. VS2010 MFC中 Date Time Picker控件的使用

    1. 在工具箱中找到Date Time Picker控件,然后拖放到对话框上. 2. 在其属性中按自己的需求做一些设置. Format 属性:Long Date (长日期):****年**月**日 S ...

  10. ElasticSearch的备份迁移方案

    使用插件repository-hdfs插件进行测试 下载地址: https://oss.sonatype.org/content/repositories/snapshots/org/elastics ...