Sharp upper and lower bounds on the length of general Davenport-Schinzel sequences