The swelling of polymers in random matrices is studied using computer simulations and percolation theory. The model system consists of freely jointed hard sphere chains in a matrix of hard spheres fixed in space. The average size of the polymer is a nonmonotonic function of the matrix volume fraction, phi(m). For low values of phi(m) the polymer size decreases as phi(m) is increased but beyond a certain value of phi(m) the polymer size increases as phi(m) is increased. The qualitative behavior is similar for three different types of matrices. In order to study the relationship between the polymer swelling and pore percolation, we use the Voronoi tessellation and a percolation theory to map the matrix onto an irregular lattice, with bonds being considered connected if a particle can pass directly between the two vertices they connect. The simulations confirm the scaling relation R(G) approximately (p-p(c))(delta(0))N(nu), where R(G) is the radius of gyration, N is the polymer degree of polymerization, p is the number of connected bonds, and p(c) is the value of p at the percolation threshold, with universal exponents delta(0)(approximately = -0.126+/-0.005) and nu(approximately = 0.6+/-0.01). The values of the exponents are consistent with predictions of scaling theory.