A combinatorial description of finite O-sequences and aCM genera