Children’s Queue
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10272 Accepted Submission(s): 3289
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?
/******************************
*
* acm: hdu-1297
*
* title: Children’s Queue
*
* time: 2014.5.18
*
******************************/
//考察遞推求解
#include <stdio.h>
#include <stdlib.h>
int fun(int n)
{
int res;
if (n == 0) //特殊處理
{
res = 1;
}
else if (n == 1)
{
res = 1;
}
else if (n == 2)
{
res = 2;
}
else if (n == 3)
{
res = 4;
}
else
{
res = fun(n-1) + fun(n-2) + fun(n-4);
}
return res;
}
int main()
{
int n;
while (~scanf("%d", &n))
{
printf("%d\n", fun(n));
}
return 0;
}
/******************************
*
* acm: hdu-1297
*
* title: Children’s Queue
*
* time: 2014.5.18
*
******************************/
//考察遞推求解
//本題打表求解
#include <stdio.h>
#include <stdlib.h>
#define ll __int64
ll Array[1000];
void fun(int n)
{
int i;
Array[0] = 1;
Array[1] = 1;
Array[2] = 2;
Array[3] = 4;
for (i = 4; i < n; i++)
{
Array[i] = Array[i-1] + Array[i-2] + Array[i-4];
}
}
int main()
{
int n;
fun(1001);
while (~scanf("%d", &n))
{
printf("%I64d\n", Array[n]);
}
return 0;
}