Skip to content

Instantly share code, notes, and snippets.

@jalola
Last active October 28, 2018 05:23
Show Gist options
  • Save jalola/5720738 to your computer and use it in GitHub Desktop.
Save jalola/5720738 to your computer and use it in GitHub Desktop.
//alpha = 1; beta = 3.14
private static long retrieval(double x) {
createPascal((int) x);
long sum = 0;
int level = (int) (x / beta) - 1; // first level
int k = level;
int remember = 0;
while (k >= 0) {
double delta = x - (level - k) * alpha - k * beta; // the last P will be processed first
if (delta <= 4) {
sum += pascal[level][k] - remember; // add pascal to sum
k--;
remember = 0;
} else {
remember += pascal[level][k+1];
level++; // increase level to 1 because delta is not small enough
k++;
}
}
return sum;
}
private static void createPascal(int n) {
pascal = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0 || j == i) {
pascal[i][j] = 1;
} else {
pascal[i][j] = pascal[i - 1][j - 1] + pascal[i - 1][j];
}
}
}
}
@quangnguyenbh
Copy link

cúc cu

@jalola
Copy link
Author

jalola commented Jun 6, 2013

ủa viết ở đây được hả :D
tao thấy mày xài tao bắt chước xài :">

@quangnguyenbh
Copy link

khà khà

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment