Dynamic programming/BigInteger/JAVA