State transformations and Hamiltonian structures for optimal control in discrete systems