The circumference c(G) of a graph G is the length of a longest cycle in G and the matching number α′(G) is the maximum size of a matching in G. In 1959, Erdős and Gallai determined the maximum size of graphs with given c(G) or α′(G). Let Kr1,…,rs denote the complete multipartite graph with class sizes r1,…,rs and δ(G) be the minimum degree of G. In this paper, we determine the maximum number of copies of Kr1,…,rs in a 2-connected n-vertex graph G with given c(G) and δ(G)≥k. The corresponding problem for an n-vertex graph G with given α′(G) and δ(G)≥k is also addressed. As a corollary of our main results, we determine the maximum number of copies of Kr1,…,rs in an n-vertex graph with given c(G) or α′(G). In addition, the corresponding problems for graphs with given detour order are solved as well.