Dinosaurs had already been in decline for around 50 million years by the time they were wiped out by a giant asteroid strike, scientists have discovered.