HDOJ/HDU 1297 Children’s Queue(推导~大数)
发布日期:2021-06-29 13:35:47
浏览次数:2
分类:技术文章
本文共 1830 字,大约阅读时间需要 6 分钟。
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 3Sample Output
1 2 4题意:
就是n个人,站成一排。 有一个要求,(F)女生不能单独一个人站在男生之间。 可以没有女生。输出有多少种站法;
(不考虑人与人的不同,只考虑位置和男女区别) (如果一排以MF结尾是不合法的)分析:
假如n个人的站法为db[n]; 由前面的推导出db[n]。 db[n-1]结尾添加一个M,是一定可以的。 db[n-2]结尾添加FF,也是一定可以的。 添加MF不可以,添加MM也是可以的(但是这个情况和db[n-1]中重复了),添加FM也是和db[n-1]+M重复了。在不可以序列后面加上FF(MF不可以,加上FF),成为合法,
所以db[n-4]后面+MFFF可以, 其实加一个F也能构成合法,但是这种情况包含在db[n-2](相当与+FF)里面;所以递推方程式db[n] =db[n-1] + db[n-2] + db[n-4];
db[i] 中保存的都是合法序列数。
Java大数秒A~~~
import java.math.BigInteger;import java.util.Scanner;public class Main{ static BigInteger db[] = new BigInteger[1001]; public static void main(String[] args) { dabiao(); Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int n =sc.nextInt(); System.out.println(db[n]); } } private static void dabiao() { db[0]=new BigInteger("1"); db[1]=new BigInteger("1"); db[2]=new BigInteger("2"); db[3]=new BigInteger("4"); db[4]=new BigInteger("7"); for(int i=5;i
转载地址:https://chenhx.blog.csdn.net/article/details/51472495 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
做的很好,不错不错
[***.243.131.199]2024年04月14日 23时00分28秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
电气毕业生在国家电网都干啥工作?
2021-07-02
为什么LED灯会越用越暗?
2019-04-29
知乎热议:嵌入式开发中C++好用吗?
2019-04-29
这100道Linux常见面试题,看看你会多少?
2019-04-29
嵌入式开发中常用的几种通信接口总结
2019-04-29
为什么你学C++这么难?
2019-04-29
无人机破巡检难题,秒变电网卫士
2019-04-29
五年,我成为了一名嵌入式工程师。
2019-04-29
2020年电赛题目,命题专家们怎么看?
2019-04-29
PCB元器件摆放不可忽略的10个技巧
2019-04-29
掌握AI核心技术没有秘籍,能自己创造就是王道
2019-04-29
大学老师的月薪多少?实话实说:4万多一点……
2019-04-29
2020年电赛题目,命题专家权威解析!
2019-04-29
写论文,这个神器不能少!
2019-04-29
现在做硬件工程师还有前途吗?
2019-04-29
华为被超越!这家公司成中国最大智能手机制造商,不是小米!
2019-04-29
芯片为什么持续缺货?
2019-04-29
美国无人机在火星首飞成功,创造历史,3米飞行高度悬停30秒
2019-04-29
缺货涨价很久的MCU的国产和国外厂家汇总!(80家)
2019-04-29
华为重磅反击,鸿蒙来了!
2019-04-29