hdu 1297
Children’s Queue |
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) |
Total Submission(s): 959 Accepted Submission(s): 534 |
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 |
Sample Output
1 大数处理加dP,,dp的话f[n]=f[n-1]+f[n-2]+f[n-4]
假设当前要加入第n个学生,如果他是男生,则加入对前面的序列都不会构成影响,
即为f[n-1],假如他是女生,为保证合法,她前面的那个也就是第n-1个也必须是
女生,接下来分两种情况讨论,如果第n-2个及以前的都合法,那么显然加入最后
这两个女生也是合法的额,但是如果不合法呢?很明显,如果不合法,问题应该出在
尾部,也就是原来f[n-2]不合法,但是加入最后两个女生后也就变得合法了(这句话
很关键),那么其只能为f[n-4]+男+女,所以即可得到公式
其实这个讨论的关键在于确定最后两个为女生才能保证合法
#include<iostream>
#include<cstdio> #include<cstring> using namespace std; long long dp[1001][1001]; int main() { int n; memset(dp,0,sizeof(dp)); dp[1][0]=1;dp[1][1]=1; dp[2][0]=1;dp[2][1]=2; dp[3][0]=1;dp[3][1]=4; dp[4][0]=1;dp[4][1]=7; for(int i=5;i<=1000;i++) { int j,t=dp[i-1][0]; for(j=1;j<=t;j++) { dp[i][j]+=dp[i-1][j]+dp[i-2][j]+dp[i-4][j]; if(dp[i][j]>=10) { dp[i][j+1]+=dp[i][j]/10; dp[i][j]%=10; } } while(dp[i][j]>=10) { dp[i][j+1]+=dp[i][j]/10; dp[i][j]%=10; j++; } j=1000; while(!dp[i][j]) j--; dp[i][0]=j; } while(cin>>n) { for(int i=dp[n][0];i>=1;i--) cout<<dp[n][i]; cout<<endl; } return 0; } |
hdu 1297的更多相关文章
- Children’s Queue HDU 1297 递推+大数
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1297 题目大意: 有n个同学, 站成一排, 要求 女生最少是两个站在一起, 问有多少种排列方式. 题 ...
- HDOJ/HDU 1297 Children’s Queue(推导~大数)
Problem Description There are many students in PHT School. One day, the headmaster whose name is Pig ...
- HDU 1297 Children’s Queue (递推、大数相加)
Children’s Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU——PKU题目分类
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...
- hdu 1465:不容易系列之一(递推入门题)
不容易系列之一 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- [转] HDU 题目分类
转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...
- HDU ACM 题目分类
模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
随机推荐
- (0)c++入门——认识指针与数组——指针即是内存中地址。
初识指针 首先需要了解一个概念,计算机的内存(或者说是寄存器)都是有地址的. <c++ primer plus>一书P37中提到这样一个概念:为把信息存储在计算机中,程序必须记录3个基本属 ...
- Python三大主流框架的对比
相信做Python这一块的程序员都有听说这三个框架,就像神一样的存在,每一个框架的介绍我就不写出来了,感兴趣可以自己百度了解了解!下面我就说正事 Django:Python 界最全能的 web 开发框 ...
- GTA4 EFLC cheat code
GTA4 EFLC cheat code 提示警告:您的图像设置接近或超出您的系统推荐资源限制,为了使游戏运行更加流畅推荐你降低你的图像设置. 在游戏目录新建名为 commandline的txt文本文 ...
- 使用svn遇到的问题---(在编辑器没有配置svn的前提下)
日常写代码的过程中新增了文件,一般都是继续文件的书写,写完一部分后提交 新增文件后面经常忘记了add后commit 原来是可以在commit时勾选左下角的 [show unversioned file ...
- 【Swift后台】背景介绍
在2017年11月的时候,就已经对Swift后台进行过研究,简书上发表过相应文章,那时候发表的是单纯的对Vapor文档的翻译,此次则是作为进一步研究的学习笔记来保存. Swift后台的本质,主要是Va ...
- Oracle的FIXED
今天发现一个有意思的问题,我们知道,在Oracle数据库中正常执行 select sysdate from dual 都可以返回当前主机的系统时间.正常修改系统时间,对应的查询结果也会变成修改后的系统 ...
- 1.1.EJB概述
1.EJB概述: Enterprice JavaBeans是一个用于分布式业务应用的标准服务端组件模型.采用Enterprice JavaBeans架构编写的应用是可伸的.事务性的. 多用户安全的.采 ...
- 4.5. scrapy两大爬虫类_Spider
一:Spider Spider类定义了如何爬取某个(或某些)网站.包括了爬取的动作(例如:是否跟进链接)以及如何从网页的内容中提取结构化数据(爬取item). 换句话说,Spider就是您定义爬取 的 ...
- Jumpserver1.4.1安装
第1章 CentOS环境准备 Jumpserver官网: http://docs.jumpserver.org/zh/docs/step_by_step.html 测试推荐硬件 CPU: 64位双核处 ...
- 配置lnmp时出现“file not found?
问题: 昨天测试并搭建lnmp架构,在测试过程中,挂载好测试环境时在浏览器上测试网站出现“file not found",使用命令curl时也出现”file not found", ...