Advertisement
DPELED

2012a_82que1

Feb 23rd, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.42 KB | None | 0 0
  1. public static boolean isSumOf(int[] a, int n)
  2.     {
  3.         return isSumOf(a, n, 0, "");
  4.     }
  5.  
  6.     private static boolean isSumOf(int[] a, int n, int i, String res)
  7.     {
  8.         if(n == 0){
  9.             System.out.println(res);
  10.             return true;
  11.         }
  12.         if(i == a.length || n < 0)
  13.             return false;
  14.         return isSumOf(a, n - a[i], i, res + " " + a[i]) || isSumOf(a, n, i + 1, res);
  15.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement