Eight people are sitting around a circular table. In how many ways can they reseat themselves so that nobody is seated to the immediate right of the same person as before?
As an explicit example, if they were originally seated as follows: A H B G C F D E then they can reseat themselves as follows, and no one would be sitting to the right of the same person as before: A B H C G D F E Details and Assumptions:
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
I programmed your solution for a larger N. Python: https://repl.it/@asdera1234/Dynamic-Table-Problem-Solver
What he's saying is : We exclude A, then the original question transform into the question of F(7). Plug A back, A can't sit right next to B or left next to H, so A only have 5 spots, 5F(7). Take "if BH is connected into cosideration", we regard BH as a single position. Now A has 6 position, 6F(6). Considering "if A between BC, CD, DE ,EF, EG, GH", 6F(6). Considering BH is connected, meanwhile A is between BC, CD, DE, EF, FG, GH, then 6F(5). F(8)=5F(7)+6F(6)+6F(6)+6F(5) F(n)=(n-3)F(n-1)+2(n-2)F(n-2)+(n-2)F(n-3) F(2)=0,F(3)=1,F(4)=1,F(5)=8,F(6)=36,F(7)=229,F(8)=1625
Log in to reply
I believe his recurrence relation, particularly after you explained it so well, but I'd like a little more justification for one of the moves that he makes. What gives him the right to stick two letters together, and treat them as if they were a single "person", allowing him to treat the number of permissible arrangements, that include one or two such "double persons," as either F(n - 1) or F(n - 2)?
Log in to reply
Not the most elegant explanation but hopefully convincing:
Let (*n) be the objective that after rearrangement of n persons no person remains to the right of the same person as before rearrangement. Let F(n) be the number of arrangements that satisfy (*n).
After removing A he then looked for arrangements of (BCDEFGH) which would allow him to place A in some position which meant the resulting arrangement of (ABCDEFGH) satisfied (*8)
First, for any of the F(7) permutations of (BCDEFGH) which satisfy (*7) he can place A in 5 positions to satisfy (*8).
Now onto the complications...
Next and in more detail, any arrangement of (BCDEFGH) which ends up with HB does not satisfy (*7). However, let HB = X and consider arrangements of (XCDEFG) satisfying (*6) e.g. (DFXECG). Replacing X with HB gives us an arrangement which still does not satisfy (*7) on (BCDEFGH). However, first inserting A in any of the 6 positions in e.g. (DFXECG) and then replacing X with HB gives us an arrangement which does satisfy(*8) ...
...since H is not to the right of G [else X would be to the right of G - violating (*6)], similarly C is not to the right of B; A is not the right of H nor left of B [since the last step was replacing X with HB]; the rest following trivially from (*6).
So far we have
F(8)=5F(7)+6F(6)+...?...
Next replace BC with X and consider arrangements satisfying (*6) on (XDEFGH). For each of these F(6) arrangements, replace X with BC and then place A in between B and C. So we've found a new set of F(6) permutations satisfying (*8). You can convince yourself that none of these were covered in the earlier arrangements found. Similarly by replacing each of the pairs CD, DE ,EF, EG, GH with X we get for each pair an additional F(6). So 6F(6) in total.
Penultimately replace HB with X and CD with Y and find arrangements satisfying (*5) on (XYEFG). For each of these F(5) arrangements then revert X and Y and place A in between C and D. Similarly for HB with the pairs DE,EF and FG for a total of 4F(5).
Finally, to count arrangements of (ABCDEFGH) containing HBAC: as usual remove A. Replace HBC with Z. Find arrangements of (ZDEFG) satisfying (*5). Revert Z to HBC and insert A between B and C. This and similarly for GAHB give the final 2F(5) arrangements.
{{ Note: Hu Yufan combined the previous two paragraphs, perhaps with the intuition that we are replacing 4->2 letters or 3->1 letter to end up with the same total of letters at the end, and each time only have one way to use this to construct an arrangement satisfying (*8). Or perhaps substituting HB->X and then XC->Z, in some sense replacing 4 letters (H,B,X,C) with two (X,Z).}}
You can convince yourself that there are no other 7-arrangements where we could insert A to make a (*8) arrangement.
So
F(8) = 5F(7) + 6F(6) + 6F(6) + 4F(5) + 2F(5). This gives the recurrence relation
F(n) = (n-3)F(n-1) + 2(n-2)F(n-2) + (n-4)F(n-3) + 2F(n-3)
For which my construction breaks on account of the "(n-4)" when n is 3, but F(3-3) is likewise undefined so it can be simplified as we would like to...
F(n) = (n-3)F(n-1)+2(n-2)F(n-2)+(n-2)F(n-3) valid for n > 3.
Then we find by computation F(1)=F(2)=0, F(3)=1 and by recurrence the rest.
ni shi zhen de pi
Say there are n persons. Let F(n) be the number of allowed arrangements with n persons. So we are looking for F(8).
(1) There are ( n − 1 ) ! seatings that are rotationally different. (Although most of them are not allowed).
(2) We can reduce all these seatings into groups of sequences: the candidate rearrangement a b d e f g c h becomes { d e f g } { c } { h a b } , a group of 3 sequences. With sequence, I will mean a (maximum) list of persons who are sitting next to each other in the original seating. Note that we may have to put the tail and the head into one sequence, as in the example above. There are ( k n ) distinct groups of k such sequences (choose k persons to start a new sequence). Each such a group of k sequences can be arranged in F(k) ways (other arrangements of the k sequences wouldn't "break" the seating in k sequences, but instead consist of k − 1 or even less sequences). The only exception is the sequence of all n persons. The ( 1 n ) possibilities for a single sequence a 1 a 2 . . . a n are all rotational the same.
Combined, we get 1 + k = 3 ∑ n ( k n ) ∗ F ( k ) = ( n − 1 ) !
We can now finaly resolve the F ( n ) recursively: F ( 1 ) = 1 , F ( 2 ) = 0 , F ( 3 ) = 1 , F ( 4 ) = 1 , F ( 5 ) = 8 , F ( 6 ) = 3 6 , F ( 7 ) = 2 2 9 , F ( 8 ) = 1 6 2 5 .
So the final answer to this question is: 1 6 2 5 .
Rephrasing my original solution: Take a circular strip with n letters A, B, C, ... written on it. Cut the strip k ∈ { 0 , 1 , . . . , n } times between two letters into k pieces. This can be done in ( k n ) ways. Now rearrange all pieces of the strip so that it represents a seating rearrangement without unnecessary cuts. A cut is unnecessary if both sides of a single cut are again neighbours after rearrangement. Such rearrangement can be done in F ( k ) ways. This makes F ( 1 ) = F ( 2 ) = 0 , F ( 0 ) = 1 and F ( 8 ) the answer we look for. Now all rearrangements are a one-to-one mapping to all ( n − 1 ) ! rearrangements. So
Σ k = 0 n ( k n ) F ( k ) = ( n − 1 ) !
By using this formula with n = 3 , 4 , . . . , 8 we find F ( 3 ) = 1 , F ( 4 ) = 1 , F ( 5 ) = 8 , F ( 6 ) = 3 6 , F ( 7 ) = 2 2 9 and finally F ( 8 ) = 1 6 2 5 .
Log in to reply
Consider a variant of the problem--number of ways to reseat themselves so that no one is next to his earlier neighbour. Thnks
A guess, using Stirling numbers of the first kind: The reflected arrangement given as an example in the problem is one solution, and then every transformation to all other solutions — choosing, say, 'A' as the fixed point — count up to |s(7,3)|. So then 1 + 1624 would add up to 1625. But I can't quite figure out how partitioning the other seven letters into three cycles works out.
As for how I actually got the solution, it took me just a few minutes to write a recursive program in Ruby to count the solutions , but Ruby doesn't seem to format in Brilliant. It would take me quite a bit longer to translate the program into Python, which I really don't know.
Log in to reply
Here is the Ruby unformatted: GUESTS = (0...8).to_a
def seat(arr) if arr.length == 8 (arr.last == 7) ? 0 : 1 else nxt = (arr.last + 1) % 8 cands = (GUESTS - (arr | [nxt])) cands.inject(0) do |count,e| new arr = arr + [e] count + seat(new arr) end end end
In sage, which works via Python, there is a function Arrangements which you can use to make a list of all permutations of a given list. Using the permutations of [1,...,7] one can easily check whether this leads to an allowed permutation. (The original order is [0,...,7] and 0 stays in its place to cancel out rotations.)
Log in to reply
Yes, there is something similar in Ruby. It isn't hard to program this problem, and there would be several ways to do it.
" nobody is seated to the right of the same person as before".
Does it mean among all arrangements before, or just the previous arrangement?
Log in to reply
It means from how they were originally seated, so in the example, when the people reseat themselves, A can't be to the right of B, B can't be to the right of C, and so on.
I don't understand why Stirling numbers work here. If so, I would expect the Stirling numbers also explain the number of allowed seatings with 7 persons: ∣ s ( 6 , 3 ) ∣ = 2 2 5 while F ( 7 ) = 2 2 9 .
This could be an easy solution:
from itertools import permutations
def check_rotation(l):
for i in range(len(l)-1):
if l[i+1]-l[i] == 1:
return True
return False
n = 8
counter = 0;
for l in permutations(range(n)):
if l[0] == 1:
break
if l[n - 1] == n-1:
continue
if not check_rotation(l):
counter += 1
print(counter)
I would say this question is formulated incorrectly. "nobody is seated to the right of the same person as before" this tells that nobody gets to sit again with same person on a right as before. In a group of 8 people there are only 7 other people that could sit on a right, and any other additional combination would result to at least someone have same person sit on a right.
Problem Loading...
Note Loading...
Set Loading...
我们将A除外,原问题化为F(7)的子问题,将A插回,A不能在B的右边与H的左边,A只有5个位置,5F(7)。
考虑BH相连的情况,将BH当作一个位置,此时A有6个位置,6F(6)。
考虑A在BC,CD,DE,EF,FG,GH之间,6F(6)。
考虑BH相连,并且A在BC,CD,DE,EF,FG,GH之间,6F(5)
F(8)=5F(7)+6F(6)+6F(6)+6F(5)
F(n)=(n-3)F(n-1)+2(n-2)F(n-2)+(n-2)F(n-3)
F(2)=0,F(3)=1,F(4)=1,F(5)=8,F(6)=36,F(7)=229,F(8)=1625