c语言程序代码分析
题目:Problem DescriptionThere are many students in PHT School. One day, the headmaster whose name is PigHeader wanted all students stand in a line. He prescribed that girl can not be in single. In other words, either no girl in the queue or more than one girl stands side by side. The case n=4 (n is the number of children) is like
FFFF, FFFM, MFFF, FFMM, MFFM, MMFF, MMMM
Here F stands for a girl and M stands for a boy. The total number of queue satisfied the headmaster’s needs is 7. Can you make a program to find the total number of queue with n children?
InputThere are multiple cases in this problem and ended by the EOF. In each case, there is only one integer n means the number of children (1<=n<=1000)
OutputFor each test case, there is only one integer means the number of queue satisfied the headmaster’s needs.
Sample Input 1 2 3
Sample Output 1 2 4
我提交的程序
#include
int f[1001][1000];
void add(int m)
{
int i;
for(i=0;i<100;i++)
{
f[m][i]=0;
}
for(i=1;i<=f[m-1][0];i++)
{
f[m][i]+=f[m-1][i]+f[m-2][i]+f[m-4][i];
f[m][i+1]=f[m][i]/10;
f[m][i]%=10;
}
if(f[m][f[m-1][0]+1])
{
f[m][0]=f[m-1][0]+1;
}
else
{
f[m][0]=f[m-1][0];
}
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int i;
for(i=0;i<4;i++)
{
f[i][0]=1;
}
f[0][1]=1;
f[1][1]=1;
f[2][1]=2;
f[3][1]=4;
for(i=4;i<=n;i++)
{
add(i);
}
for(i=f[n][0];i>0;i--)
{
printf("%d",f[n][i]);
}
printf("\n");
}
return 0;
这个代码虽然ac了,但是看了好久还是不懂什么意思,大家帮我分析分析。