int goal;
int[][] stateValue;
boolean isOptimal(int money, int bet, int level) { // bet <= money
return stateValue[level][money]
== stateValue[level-1][min(goal, money+bet)]
+ stateValue[level-1][money-bet];
}
double[] pref;
double upTo(int high) {
if(high < pref.length) return pref[high];
return pref[pref.length-1] + high - pref.length + 1;
}
double getInterval(int low, int high) {
return upTo(high) - (low == 0 ? 0. : upTo(low - 1));
}
int divCeil(int a, int b) { return (a + b - 1) / b; }
public double findProbability(int a, int tmp_b, int k) {
goal = tmp_b;
double[] ans = new double[goal];
stateValue = new int[k+1][goal+1];
stateValue[0][goal] = 1;
int[] spec = {0, goal};
for(int level = 1; level <= k; ++level) {
double[] old_ans = ans;
pref = old_ans;
for(int i = 1; i < pref.length; ++i)
pref[i] += pref[i-1];
ans = new double[goal+1];
// compute spec[]
int[] old_spec = spec;
spec = new int[(1 << level) + 1];
for (int i = 0; i <= (1 << level); ++i)
spec[i] = divCeil(goal * i, 1 << level);
// System.out.print("spec[] = "); write(spec);
// compute stateValue[level][]
for (int i = 0; i < (1 << level); ++i)
for (int j = spec[i]; j < spec[i + 1]; ++j)
stateValue[level][j] = i;
stateValue[level][goal] = 1 << level;
// main algorithm
for (int start = 0; start < (1 << level); ++start) {
double so_far = 0;
int[] next = new int[(1 << (level - 1)) + 1];
int[] begin = new int[(1 << (level - 1)) + 1];
for (int i = 0; i <= 1 << (level - 1); ++i) {
next[i] = old_spec[i];
begin[i] = -1;
}
for(int from = spec[start]; from < spec[start+1]; ++from) {
ans[from] = 0;
for (int i = 0; i <= 1 << (level - 1); ++i) {
if(begin[i] != -1) {
begin[i] = max(from, begin[i]);
if(begin[i] >= next[i]) begin[i] = -1;
}
while ((i == 1 << (level - 1) || next[i] < old_spec[i + 1])
&& next[i] <= 2 * from
&& (next[i] < from || isOptimal(from, next[i] - from, level))) {
if(next[i] < from) {
++next[i];
continue;
}
if(begin[i] == -1)
begin[i] = next[i];
++next[i];
}
if(begin[i] != -1) {
ans[from] += getInterval(begin[i], next[i]-1);
ans[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DIqZnJvbS0obmV4dFtpXS0xKSwgMiAqIGZyb20gLSBiZWdpbltpXSk7CgkJCQkJCX0KCQkJCQl9CgkJCQkJYW5zW2Zyb21dIC89IDIgKiAoZnJvbSArIDEpOwoJCQkJfQoJCQl9CgkJCWFuc1tnb2FsXSA9IDE7CgkJfQoJCXJldHVybiBhbnNbYV07Cgl9
Main.java:1: error: class, interface, or enum expected
int goal;
^
Main.java:2: error: class, interface, or enum expected
int[][] stateValue;
^
Main.java:3: error: class, interface, or enum expected
boolean isOptimal(int money, int bet, int level) { // bet <= money
^
Main.java:7: error: class, interface, or enum expected
}
^
Main.java:9: error: class, interface, or enum expected
double upTo(int high) {
^
Main.java:11: error: class, interface, or enum expected
return pref[pref.length-1] + high - pref.length + 1;
^
Main.java:12: error: class, interface, or enum expected
}
^
Main.java:15: error: class, interface, or enum expected
}
^
Main.java:16: error: class, interface, or enum expected
int divCeil(int a, int b) { return (a + b - 1) / b; }
^
Main.java:17: error: class, interface, or enum expected
public double findProbability(int a, int tmp_b, int k) {
^
Main.java:19: error: class, interface, or enum expected
double[] ans = new double[goal];
^
Main.java:20: error: class, interface, or enum expected
Arrays.fill(ans, 1.);
^
Main.java:21: error: class, interface, or enum expected
stateValue = new int[k+1][goal+1];
^
Main.java:22: error: class, interface, or enum expected
stateValue[0][goal] = 1;
^
Main.java:23: error: class, interface, or enum expected
int[] spec = {0, goal};
^
Main.java:24: error: class, interface, or enum expected
for(int level = 1; level <= k; ++level) {
^
Main.java:24: error: class, interface, or enum expected
for(int level = 1; level <= k; ++level) {
^
Main.java:24: error: class, interface, or enum expected
for(int level = 1; level <= k; ++level) {
^
Main.java:26: error: class, interface, or enum expected
pref = old_ans;
^
Main.java:27: error: class, interface, or enum expected
for(int i = 1; i < pref.length; ++i)
^
Main.java:27: error: class, interface, or enum expected
for(int i = 1; i < pref.length; ++i)
^
Main.java:27: error: class, interface, or enum expected
for(int i = 1; i < pref.length; ++i)
^
Main.java:29: error: class, interface, or enum expected
ans = new double[goal+1];
^
Main.java:31: error: class, interface, or enum expected
int[] old_spec = spec;
^
Main.java:32: error: class, interface, or enum expected
spec = new int[(1 << level) + 1];
^
Main.java:33: error: class, interface, or enum expected
for (int i = 0; i <= (1 << level); ++i)
^
Main.java:33: error: class, interface, or enum expected
for (int i = 0; i <= (1 << level); ++i)
^
Main.java:33: error: class, interface, or enum expected
for (int i = 0; i <= (1 << level); ++i)
^
Main.java:37: error: class, interface, or enum expected
for (int i = 0; i < (1 << level); ++i)
^
Main.java:37: error: class, interface, or enum expected
for (int i = 0; i < (1 << level); ++i)
^
Main.java:37: error: class, interface, or enum expected
for (int i = 0; i < (1 << level); ++i)
^
Main.java:38: error: class, interface, or enum expected
for (int j = spec[i]; j < spec[i + 1]; ++j)
^
Main.java:38: error: class, interface, or enum expected
for (int j = spec[i]; j < spec[i + 1]; ++j)
^
Main.java:40: error: class, interface, or enum expected
stateValue[level][goal] = 1 << level;
^
Main.java:42: error: class, interface, or enum expected
for (int start = 0; start < (1 << level); ++start) {
^
Main.java:42: error: class, interface, or enum expected
for (int start = 0; start < (1 << level); ++start) {
^
Main.java:42: error: class, interface, or enum expected
for (int start = 0; start < (1 << level); ++start) {
^
Main.java:44: error: class, interface, or enum expected
int[] next = new int[(1 << (level - 1)) + 1];
^
Main.java:45: error: class, interface, or enum expected
int[] begin = new int[(1 << (level - 1)) + 1];
^
Main.java:46: error: class, interface, or enum expected
for (int i = 0; i <= 1 << (level - 1); ++i) {
^
Main.java:46: error: class, interface, or enum expected
for (int i = 0; i <= 1 << (level - 1); ++i) {
^
Main.java:46: error: class, interface, or enum expected
for (int i = 0; i <= 1 << (level - 1); ++i) {
^
Main.java:48: error: class, interface, or enum expected
begin[i] = -1;
^
Main.java:49: error: class, interface, or enum expected
}
^
Main.java:50: error: class, interface, or enum expected
for(int from = spec[start]; from < spec[start+1]; ++from) {
^
Main.java:50: error: class, interface, or enum expected
for(int from = spec[start]; from < spec[start+1]; ++from) {
^
Main.java:52: error: class, interface, or enum expected
for (int i = 0; i <= 1 << (level - 1); ++i) {
^
Main.java:52: error: class, interface, or enum expected
for (int i = 0; i <= 1 << (level - 1); ++i) {
^
Main.java:52: error: class, interface, or enum expected
for (int i = 0; i <= 1 << (level - 1); ++i) {
^
Main.java:55: error: class, interface, or enum expected
if(begin[i] >= next[i]) begin[i] = -1;
^
Main.java:56: error: class, interface, or enum expected
}
^
Main.java:62: error: class, interface, or enum expected
continue;
^
Main.java:63: error: class, interface, or enum expected
}
^
Main.java:66: error: class, interface, or enum expected
++next[i];
^
Main.java:67: error: class, interface, or enum expected
}
^
Main.java:71: error: class, interface, or enum expected
ans[from] += getInterval(2*from-(next[i]-1), 2 * from - begin[i]);
^
Main.java:72: error: class, interface, or enum expected
}
^
Main.java:75: error: class, interface, or enum expected
}
^
Main.java:78: error: class, interface, or enum expected
}
^
Main.java:80: error: class, interface, or enum expected
}
^
60 errors