您的位置:首页 > 其它

UVA 11427 Expect the Expected(DP+概率)

2016-01-28 16:18 330 查看
链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35396

【思路】

  DP+概率

  见白书。

【代码】

#include<cstdio>
#include<cstring>
using namespace std;

const int N = 100+10;

int n,a,b;
double f

;

int main() {
int T,kase=0;
scanf("%d",&T);
while(T--) {
scanf("%d/%d%d",&a,&b,&n);
double p=(double)a/b;
memset(f,0,sizeof(f));
f[0][0]=1;
for(int i=1;i<=n;i++)
for(int j=0;j*b<=a*i;j++) {
f[i][j]=f[i-1][j]*(1-p);
if(j) f[i][j] += f[i-1][j-1]*p;
}
double Q=0;
for(int j=0;j*b<=a*n;j++) Q += f
[j];
printf("Case #%d: %d\n",++kase,(int)(1/Q));
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: