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. Senparc.Weixin.TenPay 正式发布

    微信支付刚出来的时候,和公众号的绑定关系很深(甚至旧版本使用的就是公众号的appId),随着微信生态的逐步丰富,微信支付越来越成为一个独立的平台,同时服务于公众号.小程序.开放平台.企业号/企业微信等 ...

  2. 【高速接口-RapidIO】1、RapidIO协议概述

    一.RapidIO背景介绍 RapidIO是由Motorola和Mercury等公司率先倡导的一种高性能. 低引脚数. 基于数据包交换的互连体系结构,是为满足和未来高性能嵌入式系统需求而设计的一种开放 ...

  3. Redis 指令 学习笔记

    Redis 什么是Redis redis是一种nosql数据库,他的数据是保存在内存中,同时redis可以定时把内存数据同步到磁盘,即可以将数据持久化,还提供了多个语言的API,操作比较方便 安装re ...

  4. 【vim】模式与模式切换

    很多初学者启动vim后,不知道怎么输入字符:按了半天字母,结果屏幕还是空的. vim和记事本或WORD不一样,不是一打开后就可以输入文字,此时它处于正常模式. vim一共有4个模式: 正常模式 (No ...

  5. (webpack系列二)webpack打包优化探索

    虽然webpack的已经升级到了webpack4,而我们目前还在使用webpack3,但其中的优化点都大同小异,升级后同样适用. 性能优化初步原则 减小代码量 减小请求数 最大化利用浏览器缓存 这三条 ...

  6. nginx介绍(三) 配置篇

    3. nginx配置 nginx配置系统受益于Igor Sysoev(nginx创始人)在Apache(阿帕奇软件基金会)的经历.Igor Sysoev洞察出可扩展的配置系统对于一个web服务器来说是 ...

  7. java字符流操作flush()方法及其注意事项

    java字符流操作flush()方法及其注意事项   flush()方法介绍 查阅文档可以发现,IO流中每一个类都实现了Closeable接口,它们进行资源操作之后都需要执行close()方法将流关闭 ...

  8. TOMCAT源码分析(转)

    前言:   本文是我阅读了TOMCAT源码后的一些心得. 主要是讲解TOMCAT的系统框架, 以及启动流程.若有错漏之处,敬请批评指教!建议:   毕竟TOMCAT的框架还是比较复杂的, 单是从文字上 ...

  9. Unity中控制天空盒移动的解决办法

    为了使天空盒更真实,需要控制天空盒动态旋转. 网上找到的方法是: float num = RenderSettings.skybox.GetFloat("_Rotation"); ...

  10. 【干货】利用MVC5+EF6搭建博客系统(四)(上)前后台页面布局页面实现,介绍使用的UI框架以及JS组件

    一.博客系统进度回顾以及页面设计 1.1页面设计说明 紧接前面基础基本完成了框架搭建,现在开始设计页面,前台页面设计我是模仿我博客园的风格来设计的,后台是常规的左右布局风格. 1.2前台页面风格 主页 ...