CSharp 实现最长递增子序列 源代码
时间: 2024-05-15 09:20:09 浏览: 6
好的,这是一个计算机科学问题,下面是 C# 实现最长递增子序列的源代码:
```
using System;
public class LongestIncreasingSubsequence
{
public static int LongestIncreasingSubsequenceLength(int[] arr)
{
int[] lis = new int[arr.Length];
int max = 0;
for (int i = 0; i < arr.Length; i++)
{
lis[i] = 1;
for (int j = 0; j < i; j++)
{
if (arr[i] > arr[j] && lis[i] < lis[j] + 1)
{
lis[i] = lis[j] + 1;
}
}
if (lis[i] > max)
{
max = lis[i];
}
}
return max;
}
public static void Main(string[] args)
{
int[] arr = { 10, 22, 9, 33, 21, 50, 41, 60 };
Console.WriteLine("Length of longest increasing subsequence is " + LongestIncreasingSubsequenceLength(arr));
}
}
```
希望这个源代码能够帮到您。现在,请问您还有其他的问题吗?