# NYOJ 923 Children’s Queue

245人阅读 评论(0)

## Children’s Queue

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?

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)

For each test case, there is only one integer means the number of queue satisfied the headmaster’s needs.

1
2
3

1
2


4

**借鉴来源  http://blog.csdn.net/xujinsmile/article/details/7364307

1）前面n-2个可以按n-2个的时候的规则来，完全可以，即是F（n-2）；

2）但是即使前面n-2个人不是合法的队列，加上两个女生也有可能是合法的。当第n-2是女孩而n-3是男孩的情况，可能合法，情况总数为F（n-4）;

#include <iostream>
#include <string>
using namespace std;
string add(string s1,string s2)//大数加法
{
int i,l,la,lb;
string max,min;
if(s1.size()>=s2.size())
{
max = s1;
min = s2;
}else
{
max = s2;
min = s1;
}
la = max.size();lb = min.size();
l = la - 1;
for(i=lb-1;i>=0;i--,l--)
{
max[l] += min[i]-'0';
}
for(i=la-1;i>=1;i--)
{
if(max[i]>'9')
{
max[i] -=10;
max[i-1] += 1;
}
}
if(max[0]>'9')
{
max[0] -= 10;
max = '1'+max;
}
return max;
}
int main()
{
int n,i;
string a[1001];
a[0] = "1";
a[1] = "1";
a[2] = "2";
a[3] = "4";
a[4] = "7";
for(i=5;i<1001;i++)
while(cin>>n)
cout<<a[n]<<endl;
return 0;
}

个人资料
等级：
访问量： 2万+
积分： 1177
排名： 4万+