Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. const long long NEGINF = numeric_limits<long long>::min();
  2. int n, m, A[100], B[100];
  3. int cache[101][101];
  4. int jlis(int indexA, indexB){
  5. int& ret = cache[indexA+1][indexB+1];
  6. if(ret != -1) return ret;
  7.  
  8. ret = 2;
  9. long long a = (indexA == -1 ? NEGINF : A[indexA]);
  10. long long b = (indexB == -1 ? NEGINF : B[indexB]);
  11. long long maxElement = max(a,b);
  12.  
  13. for(int nextA = indexA + 1; nextA < n; ++nextA)
  14. if(maxElement < A[nextA])
  15. ret = max(ret, jlis(nextA, indexB) + 1);
  16. for(int nextB = indexB + 1; nextB < m; ++nextB)
  17. if(maxElement < B[nextB])
  18. ret = max(ret, jlis(indexA, nextB) + 1);
  19. return ret;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement