Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace program_test
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int n = int.Parse(Console.ReadLine());
  13. for (int i = 1; i <= n; i++)
  14. {
  15. drum(n, i);
  16. }
  17. }
  18. public static void drum(int n,int k)
  19. {
  20. int[] solutie = new int[k];
  21. int nivel = 0;
  22. solutie[0] = 0;
  23. while (nivel > -1)
  24. {
  25. bool gasit = false;
  26. while (!gasit && solutie[nivel] < n)
  27. {
  28. solutie[nivel]++;
  29. gasit = Validare(solutie,nivel,k,n);
  30. }
  31. if (!gasit)
  32. {
  33. nivel--;
  34. }
  35. else
  36. {
  37. if (nivel == k - 1)
  38. {
  39. bool valid = true;
  40. for (int i = 0; i < k-1; i++)
  41. {
  42. if (solutie[i+1]-solutie[i]>2)
  43. {
  44. valid = false;
  45. break;
  46. }
  47. }
  48. if (valid)
  49. Afisare(solutie, k);
  50. }
  51. else
  52. {
  53. nivel++;
  54. solutie[nivel] = solutie[nivel-1];
  55. }
  56. }
  57. }
  58. }
  59. public static bool Validare(int[] sol,int nivel,int k,int n)
  60. {
  61. if (nivel == k - 1 && sol[nivel] != n)
  62. return false;
  63. if (nivel == 0 && sol[nivel] != 1)
  64. return false;
  65. return true;
  66. }
  67. public static void Afisare(int[] A,int nA)
  68. {
  69. for (int i = 0; i <nA; i++)
  70. {
  71. Console.Write(A[i] + " ");
  72. }
  73. Console.WriteLine();
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement