The problem with your code is function *ncr()*
It can easily go overflow when *n* is too big.
Here is one fix for *cnr()* and it allows you to pass test 2 (still failing
test 3 because your solution demands too much memory and time to finish)
*static int ncr(int n,int r) {*
* int result = 1;*
* r = Math.min(r, n - r);*
* for (int i = 1; i <= r; i++) {*
* result = result * (n - i + 1) / i;*
* // Once result is bigger than 1e9*
* // there is no need to calculate its actual value*
* if (result > 1000000000) {*
* return 1000000000;*
* }*
* }*
* return result;*
*}*
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/83125600-3672-434d-861a-bb0138608cde%40googlegroups.com.