views:

59

answers:

2

I am trying to solve a combinatorics problem, it seems easy, but i am having some trouble with it.

If i have at most X tables, and N persons to sit on the tables, Each table can have 1 to N seating places, and I can only sit persons in one side of a rectangular table( so the order how people sit matters).

I want to make a code that can calculate all the distributions of seating places from 1 up to K tables.

For example, if I have 12 persons and 1 table i have 479001600 ways of seating persons( thats easy to calculate I've used Factorial of 12).

But if I have 12 persons and 3 tables i have 4390848000 ways of seating persons. I've tried different solutions but i was not able to find the correct one.

I've tried to divided the 12 in 3, then o use factorial of the result (it didnt work), i've tried to use 12! * 3( it didn't work too).

Can some one give me a tip in a algorithm that i can use?

+2  A: 
KennyTM
+3  A: 

Read an article about Lah Numbers, it should help.

Roman
Thanks, I was able to solve it with the Lah Numbers.
@peiska: you're welcome.
Roman