2. Calculate the probabilities separately
When X=0, we can see that Party A and Party B are a team, and they are all arranged. Party A and Party B are interchanged, so when multiplied by 2, the probability is A22*A44/A55=2/5.
When x=3, A and B are interchanged, and the other three are all arranged. The probability is A22 * A33/A55 =110.
When X=2, there are only two positions, A and B, and the other three positions are all arranged. The probability is 2*A22*A33/A55= 1/5.
When X= 1, three positions of Party A and Party B can be interchanged, and the other three positions are all arranged. The probability is 3*A22*A33/A55=3/ 10.
So the expected value is 0 * 2/5+3 *110+2 *1/5+1*1/4 = 0.3+0.4 =1.