fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <memory.h>
  4. #include <algorithm>
  5. using namespace std;
  6. int n;
  7. int arr[1100];
  8. int catche[1200];
  9. int dp(int start) {
  10. if (start>=n) {
  11. return 0;
  12. }
  13. int& ret = catche[start];
  14. if (ret != -1) return ret;
  15.  
  16. ret = 1;
  17. for (int i = start + 1; i < n; i++) {
  18. if (arr[i] < arr[start]) ret = max(ret, 1+dp(i));
  19. // 특정 지점 (start)보다 작은 지점에서의 길이+1
  20. else ret = max(ret, dp(i));
  21. // 특정 지점 (start)보다 작지 않은 지점에서의 길이
  22. }
  23. return ret;
  24. }
  25.  
  26. int main() {
  27. cin >> n;
  28. memset(catche, -1, sizeof(catche));
  29. for (int i = 0; i < n; i++) cin >> arr[i];
  30. cout << dp(0);
  31. }
  32.  
  33.  
Success #stdin #stdout 0s 4364KB
stdin
4
2 1 2 1
stdout
3