Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace program_test
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- for (int i = 1; i <= n; i++)
- {
- drum(n, i);
- }
- }
- public static void drum(int n,int k)
- {
- int[] solutie = new int[k];
- int nivel = 0;
- solutie[0] = 0;
- while (nivel > -1)
- {
- bool gasit = false;
- while (!gasit && solutie[nivel] < n)
- {
- solutie[nivel]++;
- gasit = Validare(solutie,nivel,k,n);
- }
- if (!gasit)
- {
- nivel--;
- }
- else
- {
- if (nivel == k - 1)
- {
- bool valid = true;
- for (int i = 0; i < k-1; i++)
- {
- if (solutie[i+1]-solutie[i]>2)
- {
- valid = false;
- break;
- }
- }
- if (valid)
- Afisare(solutie, k);
- }
- else
- {
- nivel++;
- solutie[nivel] = solutie[nivel-1];
- }
- }
- }
- }
- public static bool Validare(int[] sol,int nivel,int k,int n)
- {
- if (nivel == k - 1 && sol[nivel] != n)
- return false;
- if (nivel == 0 && sol[nivel] != 1)
- return false;
- return true;
- }
- public static void Afisare(int[] A,int nA)
- {
- for (int i = 0; i <nA; i++)
- {
- Console.Write(A[i] + " ");
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement