Implicit variational principle for contact Hamiltonian systems