solve the uva 322 ships problem