Context-Based Semantic Communication via Dynamic Programming