首页 > 代码库 > uva 11427 Expect the Expected

uva 11427 Expect the Expected

https://vjudge.net/problem/UVA-11427

 

大佬题解:

http://www.cnblogs.com/xiong-/archive/2013/08/14/3258476.html

 

#include<cstring>#include<cstdio>using namespace std;double    Q,dp[101][101],p;int main(){    int t,a,b,n;    scanf("%d",&t);    for(int tt=1;tt<=t;tt++)    {        scanf("%d/%d%d",&a,&b,&n);        memset(dp,0.0,sizeof(dp));        dp[0][0]=1.0; p=1.0*a/b;        for(int i=1;i<=n;i++)         for(int j=0;j*b<=i*a;j++)           {               dp[i][j]=dp[i-1][j]*(1-p);               if(j) dp[i][j]+=dp[i-1][j-1]*p;           }        Q=0.0;        for(int i=0;i*b<=n*a;i++) Q+=dp[n][i];        printf("Case #%d: %d\n",tt,(int)(1/Q));    }}

 

uva 11427 Expect the Expected