标签:
Time Limit: 10000MS | Memory Limit: 64000K | |
Total Submissions: 3379 | Accepted: 1672 | |
Case Time Limit: 2000MS | Special Judge |
Description
Input
Output
Sample Input
1 2
Sample Output
3.0000
Source
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 5 using namespace std; 6 7 const int maxn=1010; 8 const int maxs=1010; 9 10 double dp[maxs][maxn]; 11 12 int n,s; 13 14 inline double ret(double x,double y) 15 { 16 return x*y/((double)n*s); 17 } 18 19 int main() 20 { 21 while(~scanf("%d%d",&n,&s)) 22 { 23 dp[0][0]=0.0; 24 for(int i=0;i<=s;i++) 25 { 26 for(int j=0;j<=n;j++) 27 { 28 dp[i][j]=0.0; 29 if(i>0&&j>0) 30 dp[i][j]+=ret(i,j)*dp[i-1][j-1]; 31 if(i>0) 32 dp[i][j]+=ret(i,n-j)*dp[i-1][j]; 33 if(j>0) 34 dp[i][j]+=ret(j,s-i)*dp[i][j-1]; 35 if(i!=0||j!=0) 36 { 37 dp[i][j]+=1.0; 38 dp[i][j]=dp[i][j]/(1.0-ret(s-i,n-j)); 39 } 40 } 41 } 42 printf("%.4f\n",dp[s][n]); 43 } 44 return 0; 45 }
标签:
原文地址:http://www.cnblogs.com/-maybe/p/4681044.html