Children’s Queue
2014-04-06 15:26
218 查看
http://acm.hdu.edu.cn/diy/contest_showproblem.php?pid=1001&cid=22706
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.
SmallBeer (CML)
杭电ACM集训队训练赛(VIII)
#include<iostream>
using namespace std;
int a[1001][300];
int main()
{ int i,j,n,k;
a[1][0] = 1;
a[2][0] = 2;
a[3][0] = 4;
a[4][0] = 7;
for(i = 5;i < 1001;i++)
{
k = 0;
for(j = 0;j < 300;j++)
{
a[i][j] = a[i-1][j] + a[i-2][j] + a[i-4][j] + k;
k = a[i][j] / 10;
a[i][j] %= 10;
}
}
while(cin >> n)
{
i = 299;
while(i >= 0 && !a
[i])
i--;
while(i >= 0)
cout << a
[i--];
cout << endl; }
return 0;}
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)#include<iostream>
using namespace std;
int a[1001][300];
int main()
{ int i,j,n,k;
a[1][0] = 1;
a[2][0] = 2;
a[3][0] = 4;
a[4][0] = 7;
for(i = 5;i < 1001;i++)
{
k = 0;
for(j = 0;j < 300;j++)
{
a[i][j] = a[i-1][j] + a[i-2][j] + a[i-4][j] + k;
k = a[i][j] / 10;
a[i][j] %= 10;
}
}
while(cin >> n)
{
i = 299;
while(i >= 0 && !a
[i])
i--;
while(i >= 0)
cout << a
[i--];
cout << endl; }
return 0;}
相关文章推荐
- duilib : write text on richedit
- EasyUI搭建前端框架
- ios-UITabBarControllerAndUINavigationController-用法
- easyUI Tabs 切换问题
- UICollectionView详解
- 关于EL表达式中requestScope和param区别
- 关于Assigning the return value of new by reference is deprecated的错误提示
- Confluence 管理未定义的页面
- Confluence 管理未定义的页面
- has been modified since the precompiled header was built IOS开发
- delegate模式——segue和delegate实现两个页面传值
- POJ 3080 Blue Jeans(KMP:最长连续公共子序列)
- Confluence 管理独立的页面
- Confluence 管理独立的页面
- spoj 375--Query On a Tree [树链剖分]
- **Leetcode_distinct-subsequences
- Metro UI 界面完全解析 (转载)
- ViewPager实现顶部菜单栏,仿最新易信UI,UI学习之路四
- apue和unp的学习之旅05——包裹函数
- POJ 2533 Longest Ordered Subsequence