Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import java.util.HashMap;
  2.  
  3.  
  4. public class ScrabbleBet {
  5. public HashMap<Long, Long> fact;
  6.  
  7. public static void main(String args[]) {
  8. System.out.println(new ScrabbleBet().estimate(2, 2, 1, 50));
  9. System.out.println(new ScrabbleBet().estimate(2, 2, 2, 50));
  10. }
  11. public double estimate(int t, int g, int w, int c) {
  12. calcFact();
  13.  
  14. double p = c/100d;
  15.  
  16. long total = (long)Math.pow(g, t);
  17. long nl = 0l;
  18. long gm = (long)g;
  19. for(long i=0; i<w; i++) {
  20. nl += choose(gm, i) * (1-p)/p;
  21. }
  22.  
  23. p = nl/total;
  24.  
  25. return Math.pow(p, t);
  26. }
  27.  
  28. long choose(long n, long m) {
  29. return (fact.get(n)/fact.get(m))/fact.get(n-m);
  30. }
  31.  
  32. void calcFact() {
  33. fact = new HashMap<Long, Long>();
  34.  
  35. fact.put(0l, 1l);
  36. for(long i=1; i<21; i++) {
  37. fact.put(i, fact.get(i-1)*i);
  38. }
  39. }
  40. }
  41.  
  42.  
  43. 3
  44. 33
  45. 168
  46. 528
  47. 1158
  48. 1.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement