fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.math.*;
  4.  
  5. class Ideone
  6. {
  7. public static BigInteger count(int n,int[]ni){
  8. if(n==0) return BigInteger.ONE;
  9. for(int i=0;i<ni.length;i++) {
  10. if(ni[i]>0) {
  11. int[] ni2 = Arrays.copyOf(ni, ni.length);
  12. ni2[i]--;
  13. ac=ac.add(count(n-1,ni2));
  14. }
  15. }
  16. return ac;
  17. }
  18.  
  19. public static void main(String[] args) {
  20. int n=5;
  21. int ni[]=new int[]{2,3,1};
  22. BigInteger res = count(n, ni);
  23. System.out.printf("n=%d ni=%s res=%s\n",n,Arrays.toString(ni),res.toString());
  24. }
  25.  
  26. }
Success #stdin #stdout 0.05s 711168KB
stdin
Standard input is empty
stdout
n=5 ni=[2, 3, 1] res=60