Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace LongestNonDecreasingSubsequence
- {
- class SubSeqLow
- {
- static void Main()
- {
- string input = Console.ReadLine();
- input = input.Trim()
- int[] nums = input.Split(' ').Select(s => int.Parse(s)).ToArray();
- List<List<int>> all = new List<List<int>>();
- List<int> max = new List<int>();
- int currIndex = 0;
- while (currIndex < nums.Length)
- {
- all.Add(new List<int>());
- int length = all.Count;
- for (int i = 0; i < length; i++)
- {
- List<int> current = new List<int>(all[i]);
- int lastIndex = current.Count - 1;
- if (current.Count > 0 && nums[currIndex] < current[lastIndex])
- {
- continue;
- }
- else
- {
- current.Add(nums[currIndex]);
- all.Add(current);
- if (current.Count > max.Count)
- {
- max = current;
- }
- }
- }
- currIndex++;
- }
- //prints best subsequence
- foreach (var item in max)
- {
- Console.Write("{0} ", item);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement