A generalization of the Motzkin-Straus theorem to hypergraphs