fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int longestIncreasingSubsequence(vector<double>& b) {
  7. int n = b.size();
  8. vector<int> dp(n, 1);
  9.  
  10. for (int i = 1; i < n; i++) {
  11. for (int j = 0; j < i; j++) {
  12. if (b[j] < b[i]) {
  13. dp[i] = max(dp[i], dp[j] + 1);
  14. }
  15. }
  16. }
  17.  
  18. int maxLength = 0;
  19. for (int i = 0; i < n; i++) {
  20. maxLength = max(maxLength, dp[i]);
  21. }
  22.  
  23. return maxLength;
  24. }
  25.  
  26. int main() {
  27. vector<double> b = {1.3, 2.1, 9.1, 4.3};
  28. int length = longestIncreasingSubsequence(b);
  29. cout << length << endl; // Kết quả: 4
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0.01s 5308KB
stdin
4 3
5 0
1 4
2 2
stdout
3