Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.55 KB | None | 0 0
  1.     public static int rec13(int sum, int k, int depth) {
  2.         if (depth > N)
  3.             return -1;
  4.         if (sum < 0)
  5.             return -1;
  6.         if (sum == 0) {
  7.             System.out.print("\n" + k + " ");
  8.             return 0;
  9.         }
  10.         for (int i = k; i <= sum; i = i + 2) {// Развлетляет рекурсию
  11.             if (sum - i == 0) {
  12.                 return rec13(sum - i, i, depth + 1);
  13.             }
  14.             int res = rec13(sum - i, i, depth + 1);
  15.             if (res == 0) {
  16.                 System.out.print(i + " ");
  17.                 //return 0;//распечатает только первую но полностью
  18.             }
  19.         }
  20.         return -1;
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement