ibragimova_mariam

Расстановка фишек

Mar 15th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1.  
  2. public class FindSequenceBySum
  3. {
  4. static int n = 5;
  5. static int m = 2;
  6. static int mm = 0;
  7. static char[] a = new char[n + 1];
  8. static int num = 0;
  9.  
  10. public static void rec(int idx)
  11. {
  12. if (idx == n)
  13. {
  14. num++;
  15. for (int i = 0; i < idx; i++)
  16. {
  17. System.out.print(a[i]);
  18. }
  19.  
  20. System.out.println();
  21. return;
  22. }
  23.  
  24.  
  25. if (idx == 0 || (a[idx - 1] != '*' && mm != m))
  26. {
  27. a[idx] = '*';
  28. mm++;
  29. rec(idx + 1);
  30. mm--;
  31. }
  32.  
  33. a[idx] = '.';
  34. rec(idx + 1);
  35. }
  36.  
  37. public static void main(String[] args)
  38. {
  39. rec(0);
  40. }
  41.  
  42. }
Add Comment
Please, Sign In to add comment