fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. unsigned long long PQ(int Q, int N)
  8. {
  9. if (Q <= 0) return 0;
  10. if (N <= 0) return 0;
  11. if (Q < N || Q > 6*N) return 0;
  12. if (N == 1) return 1;
  13. unsigned long long sum = 0;
  14. for(int i = 1; i <= 6; ++i)
  15. {
  16. sum += PQ(Q-i,N-1);
  17. }
  18. return sum;
  19. }
  20.  
  21. double P(int N, int Q)
  22. {
  23. return PQ(Q,N)/pow(6,N);
  24. }
  25.  
  26. int main()
  27. {
  28. cout << P(1,6) << endl;
  29. cout << P(4,14) << endl;
  30. }
  31.  
Success #stdin #stdout 0s 4240KB
stdin
Standard input is empty
stdout
0.166667
0.112654