/*the hat-check problem. Each of n customers gives a hat to a hat-check person at a
restaurant. The hat-check person gives the hats back to the customers in a random
order. What is the expected number of customers who get back their own hat?
*/
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int c=0;
int fac(int n)
{
int result=1;
do{
result*=n;
}while(--n);
return result;
}
int main(void)
{
int n=4;
int A[n];
for(int i=0;i<n;i++) A[i]=i;
do{
for(int i=0;i<n;i++) if(A[i]==i) c++;
//for(int i=0;i<n;i++) printf("%d ",A[i]);putchar('\n');
}while(next_permutation(A,A+n));
printf("%d\n",c/fac(n));//The answer is always 1 ,no matter what n is.
return 0;
}