Variational characterization of the critical curve for pinning of random polymers