Children’s Queue

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

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
 
题意:有n个位置,男孩女孩排队,要求女孩至少要2个在一起。
 
思路:设f[n]表示,n个人的情况。情况一、在f[n-1]的情况后面加一个男孩;情况二、在f[n-2]的情况后面加两个女孩;情况三、在f[n-3]最后是男孩(等价于在f[n-4]个个数)的后面加三个女孩;
所以:f[n]=f[n-1]+f[n-2]+f[n-4];由于数据比较大,所以采用大数加法就可以了。
 
 
 #include<stdio.h>
#include<string.h>
int f[][];
void init()
{
memset(f,,sizeof(f));
f[][]=;
f[][]=;
f[][]=;
f[][]=; for(int i=;i<=;i++)
{
int add=;
for(int j=;j<=;j++)
{
f[i][j]=f[i-][j]+f[i-][j]+f[i-][j]+add;
add=f[i][j]/;
f[i][j]%=;
if(add==&&f[i][j]==)break;
}
}
}
int main()
{
int n;
init();
while(scanf("%d",&n)!=EOF)
{
int k=;
while(!f[n][k])k--;
printf("%d",f[n][k--]);
for(;k>;k--)
{
printf("%04d",f[n][k]);
}
printf("\n");
}
return ;
}

Children’s Queue(hdu1297+递推)的更多相关文章

  1. HDU1297 Children’s Queue (高精度+递推)

    Children’s Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. HDU 1297 Children’s Queue (递推、大数相加)

    Children’s Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. (递推 大整数) Children’s Queue hdu1297

    Children’s Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. 【高精度递推】【HDU1297】Children’s Queue

    Children's Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. Children’s Queue HDU 1297 递推+大数

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1297 题目大意: 有n个同学, 站成一排, 要求 女生最少是两个站在一起, 问有多少种排列方式. 题 ...

  6. codeforces D. Queue 找规律+递推

    题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...

  7. 矩阵快速幂(queue递推)

    http://acm.hdu.edu.cn/showproblem.php?pid=2604 Queuing Time Limit: 10000/5000 MS (Java/Others)    Me ...

  8. HDOJ/HDU 1297 Children’s Queue(推导~大数)

    Problem Description There are many students in PHT School. One day, the headmaster whose name is Pig ...

  9. Flags-Ural1225简单递推

    Time limit: 1.0 second Memory limit: 64 MB On the Day of the Flag of Russia a shop-owner decided to ...

随机推荐

  1. 剑指offer面试题15:链表中倒数第K个节点

    题目:输入一个链表,输出该链表的倒数第K个节点.为了符合大多数人的习惯,本题从1开始计数,即链表尾节点是倒数第一个节点. 解题思路: 解法一:一般情况下,单向链表无法从后一个节点获取到它前面的节点,可 ...

  2. Go语言map

    map 是一种特殊的数据结构:一种元素对(pair)的无序集合,pair 的一个元素是 key,对应的另一个元素是 value,所以这个结构也称为关联数组或字典.这是一种快速寻找值的理想结构:给定 k ...

  3. java 常见面试题总结(一)

    1.Redis应用场景 答:分布式会话,分布式锁,计数器,缓存,消息队列,排行榜,最新列表. 2.如何访问一个类的私有方法? 答:使用反射进行访问,代码如下: package cn.entity; p ...

  4. openjtag 的硬件连接踩坑历程

    这个事情踩了不少坑,这个要记录一下: 1 代码的下载和编译按照下面的来:https://github.com/pulp-platform/pulp-debug-bridge 注意点: A 要最好使用p ...

  5. Express中间件的意思 next()的方法

    一.什么是express?Express是一个简洁.灵活的noode.jsWeb应用开发框架,它提供一系列强大的特性,帮助你创建各种Web和移动设备应用.Express项目的底层由许多的中间件在协同工 ...

  6. 《你不知道的JavaScript(上卷)》读书笔记

    第一次尝试用思维导图记笔记,感觉还不错~~~不过还是改不了我读书笔记写成抄书笔记的毛病 =.= 因为开始学JS的时候,一般浏览器就已经支持ES6了,所以比较喜欢使用ES6语法,let,=>等,文 ...

  7. 使用一年ESB感受

    ESB(Enterprise service bus)-----企业服务总线的简写. 目前使用的是openESB,Sun公司的开源社区提供的,集成在netbean中,使用glassFish服务器. 先 ...

  8. centos 7 mariadb安装

    centos 7 mariadb安装 1.安装MariaDB 安装命令 yum -y install mariadb mariadb-server 安装完成MariaDB,首先启动MariaDB sy ...

  9. 11张PPT介绍Paxos协议

    之前翻译了<The Part-Time Parliament>一文,论文非常经常,强烈推荐读一读原文.翻译完论文后,希望自己能用简单的描述来整理自己的理解,所以花了一些时间通过PPT的形式 ...

  10. Docker容器中开始.Net Core之路

    开始写这篇博客前,已经尝试练习过好多次Docker环境安装,.Net Core环境安装了,在这里替腾讯云做一个推广,假如我们想学习.练手.net core 或是Docker却苦于没有开发环境,服务器也 ...