Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- public class ScrabbleBet {
- public HashMap<Long, Long> fact;
- public static void main(String args[]) {
- System.out.println(new ScrabbleBet().estimate(2, 2, 1, 50));
- System.out.println(new ScrabbleBet().estimate(2, 2, 2, 50));
- }
- public double estimate(int t, int g, int w, int c) {
- calcFact();
- double p = c/100d;
- long total = (long)Math.pow(g, t);
- long nl = 0l;
- long gm = (long)g;
- for(long i=0; i<w; i++) {
- nl += choose(gm, i) * (1-p)/p;
- }
- p = nl/total;
- return Math.pow(p, t);
- }
- long choose(long n, long m) {
- return (fact.get(n)/fact.get(m))/fact.get(n-m);
- }
- void calcFact() {
- fact = new HashMap<Long, Long>();
- fact.put(0l, 1l);
- for(long i=1; i<21; i++) {
- fact.put(i, fact.get(i-1)*i);
- }
- }
- }
- 3
- 33
- 168
- 528
- 1158
- 1.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement