distance = speed*time, so distance/speed = time. The distance = 1000 miles. The closing speed of the two trains is 50 mph + 40 mph = 90 mph:
time = distance/speed = (1000 mi.)/(90 mph)
--
Another way to do it. Suppose the trains meet at time t. In that time, the first train traveled a distance d:
d = (40 mph)*t
In the same, since the trains meet at time t, the second train traveled a distance of 1000-d miles:
1000-d = (50 mph)*t
Now substitute (40 mph)*t for d:
1000 - (40t) = 50t
1000 = 90t
1000/90 = t