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. ThinkPHP 5隐藏public/index.php方法

    1.复制public下的index.php与.htaccess文件至根目录: 2.直接修改index.php,将内容修改为:<?php require 'public/index.php'; ? ...

  2. jsbridge的js封装

    /*注意:源生app需要配置jsbridge的环境,而在前端页面中需要下方封装代码,既可以达到调用app方法的功能和注册供app调用的方法1.注册方法:注册后,供app调用,注册时,同名函数,下一个会 ...

  3. 2.Git基础-仓库的获取方式与Git文件的状态变化周期(生命周期)

    1.仓库的获取 Git仓库的获取有两种方式: 1.从现有目录或者是项目中导入所有文件到Git中. 2.从一个服务器clone一个现有的Git仓库. 如果使用第一种方式,只需要在你希望被Git进行管理的 ...

  4. yum安装Elasticsearch5.x

    这里演示YUM和RPM两种方式安装Elasticsearch 下载并安装 public signing key: rpm --import https://artifacts.elastic.co/G ...

  5. .NetCore外国一些高质量博客分享

    前言 我之前看.netcore一些问题时候,用bing搜索工具搜到了一些外国人的博客.翻看以下,有学习的价值,就分享在这里了. 个人博客 andrewlock.net 最新几篇如下,一看标题就知道很有 ...

  6. Apache Pulsar简介

    Apache Pulsar What is Pulsar "Pulsar is a distributed pub-sub messaging platform with a very fl ...

  7. SpringBoot配置Cors解决跨域请求问题

    一.同源策略简介 同源策略[same origin policy]是浏览器的一个安全功能,不同源的客户端脚本在没有明确授权的情况下,不能读写对方资源. 同源策略是浏览器安全的基石. 什么是源 源[or ...

  8. MySQL索引的概念

    索引是一种特殊的文件(InnoDB数据表上的索引是表空间的一个组成部分),它们包含着对数据表里所有记录的引用指针.更通俗的说,数据库索引好比是一本书前面的目录,能加快数据库的查询速度. 索引分为聚簇索 ...

  9. Java 并发编程-再谈 AbstractQueuedSynchronizer 2:共享模式与基于 Condition 的等待 / 通知机制实现

    共享模式acquire实现流程 上文我们讲解了AbstractQueuedSynchronizer独占模式的acquire实现流程,本文趁热打铁继续看一下AbstractQueuedSynchroni ...

  10. 基于jQuery消息提示框插件Tipso

    今天要分享的这款jQuery消息提示框插件名叫Tipso,它的特点是可以定义提示框的显示位置,以及动态改变提示框的提示内容,应该说是一款相当灵活的jQuery消息提示框插件.效果图如下: 在线预览   ...