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;
- using System.Threading.Tasks;
- namespace _13.LongestIncreasSubseq
- {
- class Program
- {
- static void Main(string[] args)
- {
- var nums = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- var longestIncrease = new int[nums.Length];
- AddOnes(longestIncrease); //Променя стойността на всеки елемент на масива на "1"
- List<int> len = new List<int>();
- for (int i = 0; i < nums.Length-1; i++)
- {
- for (int j = i+1; j < nums.Length; j++)
- {
- if (nums[i]<nums[j])
- {
- longestIncrease[j] = longestIncrease[i] + 1;
- }
- }
- }
- for (int i = 0; i < longestIncrease.Length-1; i++)
- {
- if (longestIncrease[i]<longestIncrease[i+1])
- {
- len.Add(nums[i]);
- }
- }
- Console.WriteLine(string.Join(" ",len));
- }
- private static void AddOnes(int[] arr1)
- {
- for (int i = 0; i < arr1.Length; i++)
- {
- arr1[i] = 1;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement