链接: https://pan.baidu.com/s/1gpfD4XVLQ8z95Hho5rRdfw
提取码: kuv8
链接: https://pan.baidu.com/s/1gpfD4XVLQ8z95Hho5rRdfw
提取码: kuv8
using System;
using System.Linq;
using System.Collections.Generic;
namespace ConsoleApp1
{
class Program
{
public static string findSubsequence(int[] arr)
{
// `LIS[i]` stores the longest increasing subsequence of subarray
// `arr[0…i]` that ends with `arr[i]`
var LIS = new List<List<int>>();
for (int i = 0; i < arr.Length; i++)
{
LIS.Add(new List<int>());
}
// `LIS[0]` denotes the longest increasing subsequence ending at `arr[0]`
LIS[0].Add(arr[0]);
// start from the second array element
for (int i = 1; i < arr.Length; i++)
{
// do for each element in subarray `arr[0…i-1]`
for (int j = 0; j < i; j++)
{
// find the longest increasing subsequence that ends with `arr[j]`
// where `arr[j]` is less than the current element `arr[i]`
if (arr[j] < arr[i] && LIS[j].Count > LIS[i].Count)
{
LIS[i] = new List<int>();
LIS[i].AddRange(LIS[j].ToArray());
}
}
// include `arr[i]` in `LIS[i]`
LIS[i].Add(arr[i]);
}
return String.Join(" ", LIS.OrderByDescending(i => i.Count).FirstOrDefault());
}
public static void Main()
{
var arr = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
Console.WriteLine(findSubsequence(arr));
}
}
}