longest_increasing_subsequence.cpp 532 B

123456789101112131415161718192021222324252627282930
  1. #include <iostream>
  2. #include <memory.h>
  3. using namespace std;
  4. int *arr, *dp;
  5. int main() {
  6. int n, max = -1;
  7. cin >> n;
  8. arr = new int[n];
  9. dp = new int[n];
  10. memset(dp, 0x00, n*sizeof(int));
  11. for (int i = 0; i < n; ++i) {
  12. cin >> arr[i];
  13. }
  14. for (int i = 0; i < n; ++i) {
  15. for (int j = 0; j < i; ++j) {
  16. if (arr[j] < arr[i]) {
  17. dp[i] = dp[j] > dp[i] ? dp[j] : dp[i];
  18. }
  19. }
  20. ++dp[i];
  21. max = max < dp[i] ? dp[i] : max;
  22. }
  23. cout << max << endl;
  24. delete [] arr;
  25. delete [] dp;
  26. return 0;
  27. }