Optimal Dynamic Allocation of Attention