Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- /*
- * Write a recursive program for generating and printing all ordered k-element subsets from n-element set (variations Vkn).
- * Example: n=3, k=2
- * (1 1), (1 2), (1 3), (2 1), (2 2), (2 3), (3 1), (3 2), (3 3)
- */
- namespace Variation
- {
- class Variation
- {
- static void Print(int[] vector, int k)
- {
- for (int j = 0; j <= k - 1; j++)
- {
- Console.Write("{0} ", vector[j] + 1);
- }
- Console.WriteLine();
- }
- static void Variate(int index, int n, int k, int[] vector)
- {
- if (index >= k)
- {
- Print(vector, index);
- return;
- }
- for (int j = 0; j < n; j++)
- {
- vector[index] = j;
- Variate(index + 1, n, k, vector);
- }
- }
- static void Main()
- {
- int n = 3;
- int k = 2;
- int[] vector = new int[n];
- Variate(0, n, k, vector);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement