use a triangular matrix to cache