Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class LongestIncreasingSubSequence
- {
- static void Check(int[] arr, int[] indices, int k)
- {
- int count = 1;
- int result = 0;
- for (int i = 0; i < k; i++)
- {
- count++;
- result = arr.Length - count;
- if (arr[indices[i]] > arr[indices[i + 1]])
- {
- return; //Reversed because of recursion
- }
- }
- for (int i = 0; i <= k; i++) Console.Write(arr[indices[i]] + (i == k ? "\n" : " "));
- Console.WriteLine(result);
- Environment.Exit(0);
- }
- static void Combination(int[] arr, int[] indices, int k, int i, int next)
- {
- if (i > k) return;
- for (int j = next; j < arr.Length; j++)
- {
- indices[i] = j;
- if (i == k) Check(arr, indices, k);
- Combination(arr, indices, k, i + 1, j + 1);
- }
- }
- static void Main()
- {
- int[] arr = new int[int.Parse(Console.ReadLine())];
- for (int i = 0; i < arr.Length; i++) arr[i] = int.Parse(Console.ReadLine());
- int[] indices = new int[arr.Length];
- for (int i = arr.Length - 1; i >= 0; i--) Combination(arr, indices, i, 0, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment