Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static boolean sumNum(int[] a, int n)
- {
- return sumNum(a, n, 0, 0, 0,new int[a.length], new int[a.length], 0, 0);
- }
- private static boolean sumNum(int[] a, int n, int i, int s1, int s2, int[] hist1, int[] hist2, int ind1, int ind2)
- {
- if(i >= a.length)
- {
- if(s1 - s2 == n || s2 - s1 == n)
- {
- print(hist1, 0, ind1);
- System.out.println();
- print(hist2, 0, ind2);
- return true;
- }
- return false;
- }
- hist1[ind1] = a[i];
- if(sumNum(a, n, i+1, s1 + a[i], s2, hist1, hist2, ind1 + 1, ind2))
- {
- return true;
- }
- hist2[ind2] = a[i];
- return sumNum(a, n, i+1, s1, s2 + a[i], hist1, hist2, ind1, ind2 + 1);
- }
- private static void print(int[] a, int from, int to)
- {
- if(from < to)
- {
- System.out.print(a[from] + ", ");
- print(a, from+1, to);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement