转载自:https://blog.csdn.net/wongson/article/details/7974587
题目:一个骰子,6面,1个面是 1, 2个面是2, 3个面是3,问平均掷多少次能使1、2、3都至少出现一次。
解:(没学过《组合数学》的请略过)
设P(N=n)表示第n次(n>2)抛出后1,2,3都出现的概率,问题要求n的期望E(N=n).掷1的概率p=1/6,掷2的概率q=1/3,掷3的概率r=1/2.

写程序求解
#include <iostream>
- using namespace std;
- float f(float x)
- {
- return (1/(1-x)/(1-x)-1-2*x);
- }
- int main()
- {
- float p=1.0/6,q=1.0/3,r=1.0/2,e;
- e=r*(f(p+q)-f(p)-f(q))+p*(f(q+r)-f(q)-f(r))+q*(f(p+r)-f(p)-f(r));
- cout<<e<<endl;
- return 0;
- }
答案7.3