Alternating selection for dispersal and multicellularity favors regulated life cycles