fork(1) download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef long long ll;
  5.  
  6. const int MX=43;
  7.  
  8. void fnc(){
  9. array<array<ll, MX+5>, MX+5> cmb;
  10. for(int i=0; i<MX+5; i++) cmb[i][0] = 1;
  11. for(int i=1; i<MX+5; i++) for(int j=1; j<=i;j++)
  12. cmb[i][j] = cmb[i-1][j] + cmb[i-1][j-1];
  13.  
  14.  
  15. ll sm = 0;
  16. for(int i=3 ; i<=6; i++){
  17. ll w = cmb[6][i] * cmb[MX-6][6-i]; //当たりがi個の組み合わせ数
  18. sm += w;
  19. printf("%d : %6lld\n", i, w);
  20. }
  21.  
  22. printf("\n%lld / %lld --> %.15f by comb\n",
  23. sm, cmb[MX][6], 1.0*sm/cmb[MX][6]);
  24.  
  25. }
  26.  
  27. void fnc2(){
  28. vector<double> dp(8); //dp[あたり数] = 確率
  29. dp[0] =1.0;
  30. for(int i=0; i<6; i++){
  31. vector<double> np(8);
  32. for(int j=0; j<6; j++){
  33. int atr = 6-j; //残り当たり数
  34. np[j+1] += dp[j] * atr/(MX-i);
  35. np[j] += dp[j] * (MX-i-atr)/(MX-i);
  36. }
  37. dp.swap(np);
  38. }
  39. double ans =0;
  40. for(int i=3; i<7; i++) ans +=dp[i];
  41. printf("\n%.15f by dp\n", ans);
  42. }
  43.  
  44.  
  45. int main()
  46. {
  47. fnc(); //コンビネーションで求める
  48. fnc2(); //確率DPで求める
  49. }
  50.  
Success #stdin #stdout 0s 4296KB
stdin
Standard input is empty
stdout
3 : 155400
4 :   9990
5 :    222
6 :      1

165613 / 6096454 --> 0.027165463726947  by comb

0.027165463726947  by dp