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];由于数据比较大,所以采用大数加法就可以了。
 
 
  1. #include<stdio.h>
  2. #include<string.h>
  3. int f[][];
  4. void init()
  5. {
  6. memset(f,,sizeof(f));
  7. f[][]=;
  8. f[][]=;
  9. f[][]=;
  10. f[][]=;
  11.  
  12. for(int i=;i<=;i++)
  13. {
  14. int add=;
  15. for(int j=;j<=;j++)
  16. {
  17. f[i][j]=f[i-][j]+f[i-][j]+f[i-][j]+add;
  18. add=f[i][j]/;
  19. f[i][j]%=;
  20. if(add==&&f[i][j]==)break;
  21. }
  22. }
  23. }
  24. int main()
  25. {
  26. int n;
  27. init();
  28. while(scanf("%d",&n)!=EOF)
  29. {
  30. int k=;
  31. while(!f[n][k])k--;
  32. printf("%d",f[n][k--]);
  33. for(;k>;k--)
  34. {
  35. printf("%04d",f[n][k]);
  36. }
  37. printf("\n");
  38. }
  39. return ;
  40. }

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. 使用Kubeadm搭建Kubernetes(1.12.2)集群

    Kubeadm是Kubernetes官方提供的用于快速安装Kubernetes集群的工具,伴随Kubernetes每个版本的发布都会同步更新,在2018年将进入GA状态,说明离生产环境中使用的距离越来 ...

  2. Windows 10 IoT Core 17115 for Insider 版本更新

    今天,微软发布了Windows 10 IoT Core 17115 for Insider 版本更新,本次更新只修正了一些Bug,没有发布新的特性. 一些已知的问题如下: F5 driver depl ...

  3. 背水一战 Windows 10 (114) - 后台任务: 后台任务的 Demo(与 app 不同进程), 后台任务的 Demo(与 app 相同进程)

    [源码下载] 背水一战 Windows 10 (114) - 后台任务: 后台任务的 Demo(与 app 不同进程), 后台任务的 Demo(与 app 相同进程) 作者:webabcd 介绍背水一 ...

  4. Hadoop 电话通信清单

    一.实例要求 现有一批电话通信清单,记录了用户A拨打某些特殊号码(如120,10086,13800138000等)的记录.需要做一个统计结果,记录拨打给用户B的所有用户A. 二.测试样例 样例输入: ...

  5. FFmpeg 学习(二):Mac下安装FFmpeg

    一.安装ffmpeg 分为两种安装方式: 1. 命令行安装 brew install ffmpeg 2. 下载压缩包安装 去 http://evermeet.cx/ffmpeg/ 下载7z压缩包,解压 ...

  6. Java项目启动时执行指定方法的几种方式

    很多时候我们都会碰到需要在程序启动时去执行的方法,比如说去读取某个配置,预加载缓存,定时任务的初始化等.这里给出几种解决方案供大家参考. 1. 使用@PostConstruct注解 这个注解呢,可以在 ...

  7. Eclipse 配置 Tomcat 服务器

    配置Tomcat 在首先外部安装好Tomcat,然后在eclipse配置Tomcat服务器: 选择要配置的Tomcat版本: 注意:这一步如果勾选了Create a new local server ...

  8. 数据库占用cpu较高的查询

    近来看到别人的有关数据库查询cpu占用较高的sql语句(本人sql并不好),所以查询了一下资料,记录一下,便于理解和应用. 首先,将语句贴在这里 SELECT TOP 10 --平均cpu时间 tot ...

  9. mongo 更新字段值,若不存在则自动创建

    查询语句 db.getCollection("A表").update( {  "id":{$eq:11} } ,{     $set:{"a" ...

  10. 1.numpy的用法

    numpy创建ndarray对象的三种方法 1.1.list转化 In [8]: import numpy as np In [9]: a = [1,2,3,4] In [10]: x1 = np.a ...