If you have $N_+$ uplinks out of $N$ (so the Boltzmann factor is $\exp\{-\beta mga N_+\}$) the corresponding number of microstates is the binomial coefficient "$N$ choose $N_+$" or $$ \frac{N!}{N_+! N_-!}. $$$$ {N \choose N_+}=\frac{N!}{N_+! N_-!}. $$ The partition function is therefore $$ Z= \sum_{N_+=0}^N \frac{N!}{N_+! N_-!}\exp\{-\beta mga N_+\}= (1+\exp\{-\beta mga\})^N $$