Play the Dice
传送门1
传送门2
There is a dice with n sides, which are numbered from
Input
Input consists of multiple cases. Each case includes two lines.
The first line is an integer
The second line is an integer
Output
Just a real number which is the expectations of the money one can get, rounded to exact two digits. If you can get unlimited money, print inf.
Sample Input
6 1 2 3 4 5 6
0
4 0 0 0 0
1 3
Sample Output
3.50
0.00
题意
有一个正n面体骰子,给出每个面的得分。接着是m,表示丢到哪些面后可以获得再掷一次的机会,问最后得分的期望。
分析
显然这道题可以用概率dp/期望dp写
这里用另一种看起来很高端的写法.
第一次掷骰子获得分数期望显然是
运气好的话有
……
当然运气好到爆的话你会掷k次
于是 掷k次期望就是
会发现乘号前面其实是等比数列求和,其首项
于是期望为
也就是说只要记录
printf("%.2lf\n",1.0*sum/(n-m));
上面是最普通的情况
显然
n==m
时
puts("inf");
,但是别忘了
sum==0
的时候你运气再好一分都没有(
puts("0");
ps:
CODE
#include<cstdio>
#define N 205
int A[N],t;
int main() {
int n,m;
while(~scanf("%d",&n)) {
int sum=0;
for(int i=1;i<=n;i++) {
scanf("%d",&A[i]);
sum+=A[i];
}
scanf("%d",&m);
for(int i=1;i<=m;i++)scanf("%d",&t);//显然b[i]没有任何用处
if(sum==0)puts("0");
else if(n==m)puts("inf");
else printf("%.2lf\n",1.0*sum/(n-m));
}
return 0;
}