| 256 | } |
| 257 | |
| 258 | public static int total(int n) { |
| 259 | // Function to return (2n) ! / ((n+1)! * n!) |
| 260 | |
| 261 | // To keep the numbers small, we divide by i when possible to do evenly. If not, |
| 262 | // we store up the remainder and divide when possible. |
| 263 | long num = 1; |
| 264 | long rem = 1; |
| 265 | for (int i = 2; i <= n; i++) { |
| 266 | num *= (n + i); |
| 267 | rem *= i; |
| 268 | if (num % rem == 0) { |
| 269 | num /= rem; |
| 270 | rem = 1; |
| 271 | } |
| 272 | } |
| 273 | return (int)num; |
| 274 | } |
| 275 | |
| 276 | public static int countDPEff(String exp, boolean result, int start, int end, HashMap<String, Integer> cache) { |
| 277 | String key = "" + start + end; |