Qiuqiqiu  
不管道路多么崎岖坎坷,我永远不停下追逐梦想的脚步!

http://acm.hdu.edu.cn/showproblem.php?pid=1297

Children’s Queue

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4958    Accepted Submission(s): 1518


Problem Description
There 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?
 

 

Input
There 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)
 

 

Output
For 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
 

 

Author
SmallBeer (CML)
 

 

Source
杭电ACM集训队训练赛(VIII)
 

 

Recommend
lcy
 
我的理解
 
我的代码
 1 #include <stdio.h>
2 const int maxn=1000;
3 int m[1002][1000]={{0},{1,1},{1,1}},
4 f[1002][1000]={{0},{1,0},{1,1}};
5 void add(int a[],int b[],int c[])
6 {
7 int i;
8 for (i=0;i<=a[0];i++) c[i]=a[i];
9 if (b[0]>c[0]) c[0]=b[0];
10 for (i=1;i<=c[0];i++)
11 {
12 c[i]+=b[i];
13 if (c[i]>9)
14 {
15 c[i]-=10;
16 c[i+1]++;
17 }
18 if (c[c[0]+1]>0) c[0]++;
19 }
20 }
21 int main()
22 {
23 int i,n;
24 for (i=3;i<=maxn+1;i++)
25 {
26 add(m[i-1],f[i-1],m[i]);
27 add(f[i-1],m[i-2],f[i]);
28 }
29 while (scanf("%d",&n)!=EOF)
30 {
31 for (i=m[n+1][0];i>0;i--) printf("%d",m[n+1][i]);
32 printf("\n");
33 }
34 }
 
posted on 2011-10-31 21:59  Qiuqiqiu  阅读(1070)  评论(0编辑  收藏  举报