一个数学期望的题目,有dp的思想。但其实数学好的可以直接推公式。代码如下:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
double i , n , m ;
while(~scanf("%lf %lf", &m, &n))
{
double sum = 0.0 ;
for(i=1;i<=m;i++)
{
sum+=i*(pow((i/m),n)-pow((i-1)/m,n));
}
printf("%lf\n", sum);
}
return 0;
}
这里说明一下公式的由来:
假设有6个面,投掷6次
4*(pow(4/6,6)-pow(3/6,6)):表示(面数不超过4的情况--不超过3的情况)*面数
总结:好好学习数学
探讨使用数学期望解决骰子概率问题,包括输入参数解释、输出结果计算及实例解析。
.
Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice 
1325

被折叠的 条评论
为什么被折叠?



