测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A67593. 给定一个整数数组nums,找到其中最长的严格上升子序列的长度。 子序列是指从原数组中删除一些元素(或不删除)后,剩余元素保持原有顺序的序列。 该程序的时间复杂度为()1 #include <iostream>

单选题

题目描述

给定一个整数数组nums,找到其中最长的严格上升子序列的长度。 

子序列是指从原数组中删除一些元素(或不删除)后,剩余元素保持原有顺序的序列。 

该程序的时间复杂度为()

1 #include <iostream> 
2 #include <vector> 
3 #include <algorithm> 
4 using namespace std; 
5
6 int lengthOfLIS(vector<int>& nums) { 
7  int n = nums.size(); 
8  if (n == 0) return 0; 
9  vector<int> dp(n, 1); 
10
11  for (int i = 1; i < n; i++) { 
12   for (int j = 0; j < i; j++) { 
13    if (nums[i] > nums[j]) { 
14     _________________________ 
15    } 
16   } 
17  }
18  return *max_element(dp.begin(), dp.end()); 
19 } 
20
21 int main() { 
22  int n; 
23  cin >> n; 
24  vector<int> nums(n); 
25  for (int i = 0; i < n; i++) { 
26   cin >> nums[i]; 
27  } 
28
29  int result = lengthOfLIS(nums); 
30  cout << result << endl; 
31
32  return 0; 
33 }


选项(单选)