Counting and enumerating frequency tables with given margins