前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HDUOJ Children’s Queue

HDUOJ Children’s Queue

作者头像
Gxjun
发布2018-03-21 12:15:50
7620
发布2018-03-21 12:15:50
举报
文章被收录于专栏:mlml

Children’s Queue

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

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

大数。。 公式 f(x)=f(x-1)+f(x-2)-F(x-4);

代码:

代码语言:javascript
复制
 1 #include<iostream>
 2 #include<cstdio>
 3 #define maxn 250
 4 #define len 1000
 5 using namespace std;
 6 int a[len+1][maxn+1]={{1},{2},{4},{7}};
 7 int main()
 8 {
 9     int i,j,n,s,c=0;
10     for(i=4;i<=len;i++)
11     {
12         for(c=j=0;j<=maxn;j++)
13         {
14           s=a[i-1][j]+a[i-2][j]+a[i-4][j]+c;
15           a[i][j]=s%10;
16           c=(s-a[i][j])/10;
17         }
18     }
19     while(cin>>n)
20     {
21      for(i=maxn;a[n-1][i]==0;i--);
22      for(j=i;j>=0;j--)
23      {
24          printf("%d",a[n-1][j]);
25      }
26      printf("\n");
27     }
28     return 0;
29 }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2013-08-04 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Children’s Queue
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档