A probabilistic analysis of Monte Carlo algorithms for a class of counting problems