Existence of minimizers for non-quasiconvex functionals arising in optimal design