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 Scara
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("n=");
- int n = int.Parse(Console.ReadLine());
- scari(n);
- }
- public static void scari(int n)
- {
- int parImapar = 0;
- if (n % 2 == 0) parImapar = -1;
- for (int i = n; i > n / 2+parImapar; i--)
- {
- Combinari(n, i);
- }
- }
- public static void Combinari(int n, int lungime)
- {
- int[] solutie = new int[lungime];
- int nivel = 0;
- solutie[0] = 0;
- while (nivel > -1)
- {
- bool gasit = false;
- while (!gasit && solutie[nivel] < n)
- {
- solutie[nivel]++;
- gasit = Validare(solutie, nivel, lungime,n);
- }
- if (!gasit)
- {
- nivel--;
- }
- else
- {
- if (nivel == lungime - 1)
- {
- Afisare(solutie, lungime);
- }
- else
- {
- nivel++;
- solutie[nivel] = solutie[nivel - 1];
- }
- }
- }
- }
- public static void Afisare(int[] a, int lungime)
- {
- for (int i = 0; i < lungime; i++)
- {
- Console.Write(a[i] + " ");
- }
- Console.WriteLine();
- }
- public static bool Validare(int[] sol, int nivel,int k,int n)
- {
- if (nivel == k - 1)
- {
- if (sol[nivel] != n)
- {
- return false;
- }
- }
- if (sol[0] != 1) return false;
- if (nivel > 0)
- {
- if (sol[nivel] - 2 > sol[nivel - 1]) return false;
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement