Optimal Continual Learning has Perfect Memory and is NP-hard