Transition-metal hydrides: Electronic structure and the heats of formation