fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int lengthOfLIS(vector<int>& nums) {
  5. vector<int>dp(n,1);
  6. for(int i=1;i<n;i++){
  7. for(int j=0;j<i;j++){
  8. if(nums[j]<nums[i]){
  9. dp[i]= (dp[j]+1>dp[i])?dp[j]+1:dp[i];
  10. }
  11. }
  12. }
  13. return *max_element(dp.begin(),dp.end());
  14. }
  15.  
  16. //follow-up: total no of increasing sequences
  17.  
  18. int totalLIS(vector<int>& nums, int n){
  19. vector<int>dp(n,1);int ct=dp[0];
  20. for(int i=1;i<n;i++){
  21. for(int j=0;j<i;j++){
  22. if(nums[j]<nums[i]){
  23. dp[i]= dp[j]+1;
  24. }
  25. }
  26. ct+=nums[i];
  27. }
  28. return ct;
  29. }
  30. //second follow-up: have to learn segment trees
  31.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty