fork(3) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define mset(arr,x) memset(arr,x,sizeof(arr))
  6. #define rep(i,s,e) for(i=s;i<=e;i++)
  7. #define rrep(i,s,e) for(i=s;i>=e;i--)
  8.  
  9. ll dp[4010][4010];
  10. int main()
  11. {
  12. ios_base::sync_with_stdio(false);
  13. cin.tie(0);
  14.  
  15. ll N, i, j, T, M, ppll;
  16. string st;
  17.  
  18. cin >> T;
  19. rep(ppll, 1, T)
  20. {
  21. mset(dp, 0);
  22.  
  23. cin >> N >> M;
  24. rep(i, 1, N)
  25. {
  26. dp[i][0] = 1;
  27. }
  28.  
  29. rep(i, 1, N)
  30. {
  31. rep(j, 1, i-1)
  32. {
  33. if( i!=j )
  34. {
  35. dp[i][j] = dp[i-1][j] + dp[i][j-1];
  36. }
  37. }
  38. }
  39.  
  40. double anss = (double)dp[N][M];
  41. ll val = N+M;
  42.  
  43. rrep(i, M, 1)
  44. {
  45. double opop = (double)( ((double)i)/val );
  46. anss = ( anss * opop );
  47. val--;
  48. }
  49.  
  50. cout << "Case #" << ppll << ": " << setprecision(12) << anss << endl;
  51. }
  52.  
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0.03s 140864KB
stdin
2
2 1
1 0
stdout
Case #1: 0.333333333333
Case #2: 1