Test by male and female. A total of n persons (f (n) indicates the number of valid sequences when n persons exist, and ak indicates the k persons ), when a1 is a boy, f (n-1) is possible. When a1 is a girl, a2 must be a girl. When a1 and a2 are girls, a3 is a boy, f (n-3) is possible, when a1, a2, a3 are girls, a4 is boys, f (n-4) is possible, this type of push (in the following formula, 1 indicates that n is the girl, f (0) = 1), so f (n) = f (n-1) + f (n-3) + f (n-4) + f (N-5) +... + f (1) + f (0) + 1; so f (n-2) = f (n-3) + f (N-5) + f (n-6) +... + f (1) + f (0) + 1; f (n) = f (n-1) + f (n-2) + f (n-4)
[Csharp]
# Include "stdio. h"
# Include "string. h"
Int f [1001] [300];
Int main ()
{
Int I, j, n;
Int temp;
Memset (f, 0, sizeof (f ));
F [0] [0] = 1;
F [1] [0] = 1;
F [2] [0] = 2;
F [3] [0] = 4;
For (I = 4; I <= 1000; I ++)
{
Temp = 0;
For (j = 0; j <300; j ++)
{
F [I] [j] = f [I-1] [j] + f [I-2] [j] + f [I-4] [j] + temp;
Temp = f [I] [j]/10;
F [I] [j] % = 10;
}
}
Int flag;
While (scanf ("% d", & n )! = EOF)
{
Flag = 0;
For (j = 299; j> = 0; j --)
{
If (f [n] [j]! = 0) flag = 1;
If (flag = 1)
Printf ("% d", f [n] [j]);
}
Printf ("\ n ");
}
Return 0;
}