HDOJ 1297 Children’s Queue

时间:2022-09-27 23:01:10

版权声明:来自: 码代码的猿猿的AC之路 http://blog.csdn.net/ck_boss https://blog.csdn.net/u012797220/article/details/35860567

JAVA大数....

Children’s Queue

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10390    Accepted Submission(s): 3333

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
 

Author
SmallBeer (CML)
 

Source
 
import java.util.*;
import java.math.*; public class Main
{
public static void main(String[] args)
{
Scanner cin=new Scanner(System.in); BigInteger[] a=new BigInteger[1100];
a[1]=BigInteger.valueOf(1);
a[2]=BigInteger.valueOf(2);
a[3]=BigInteger.valueOf(4);
a[4]=BigInteger.valueOf(7);
for(int i=5;i<=1000;i++)
{
a[i]=a[i-4].add(a[i-2].add(a[i-1]));
} while(cin.hasNextInt())
{
int n=cin.nextInt();
System.out.println(a[n]);
}
}
}

HDOJ 1297 Children’s Queue的更多相关文章

  1. HDU 1297 Children’s Queue (递推、大数相加)

    Children’s Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. HDOJ&sol;HDU 1297 Children’s Queue&lpar;推导~大数&rpar;

    Problem Description There are many students in PHT School. One day, the headmaster whose name is Pig ...

  3. 【HDOJ】1297 Children’s Queue

    递推,最近发现自己做递推的题总是没有思路.下周多练习.对于f(n)可以在第n个位置为男生,此时共有f(n-1)种情况:若在第n个位置为女生,因此第n-1个位置也必须为女生.此时有两种情况,一种情况是在 ...

  4. 杭电ACM 1297 Children’s Queue

    这道题是排序问题,可以用递归方法解决. 计算F(n): 一:当最后一个是男孩M时候,前面n-1个随便排出来,只要符合规则就可以,即是F(n-1): 二:当最后一个是女孩F时候,第n-1个肯定是女孩F, ...

  5. Children’s Queue(hdu1297&plus;递推)

    Children’s Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...

  6. HDU1297 Children’s Queue &lpar;高精度&plus;递推&rpar;

    Children’s Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. 【高精度递推】【HDU1297】Children’s Queue

    Children's Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. Children’s Queue

    Children's Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. (递推 大整数) Children’s Queue hdu1297

    Children’s Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. H5 浏览器开发文档

    http://sja.co.uk/controlling-which-ios-keyboard-is-shown https://developer.apple.com/library/safari/ ...

  2. mybatis系列-12-多对多查询

    12.1     需求 查询用户及用户购买商品信息. 12.2     sql语句 查询主表是:用户表 关联表:由于用户和商品没有直接关联,通过订单和订单明细进行关联,所以关联表: orders.or ...

  3. &lpar;DP6&period;1&period;2&period;1&rpar;UVA 147 Dollars&lpar;子集和问题&rpar;

    /* * UVA_147.cpp * * Created on: 2013年10月12日 * Author: Administrator */ #include <iostream> #i ...

  4. USACO Section 5&period;3 Big Barn&lpar;dp&rpar;

    USACO前面好像有类似的题目..dp(i,j)=min(dp(i+1,j),dp(i+1,j+1),dp(i,j+1))+1  (坐标(i,j)处无tree;有tree自然dp(i,j)=0) .d ...

  5. php 生成&period;txt文件

    $content =array('color'=> array('blue','red','green'),'size'=> array('small','medium','large') ...

  6. jsp显示计算数值&comma; 四舍五入

    <script>document.write(Math.round(<%= rs_MFM.getInt("PVRCompl") %>/<%= rs_M ...

  7. jQuery监听事件经典例子

    关键字:jQuery监听事件经典例子  js代码:  ============================================================  $(function( ...

  8. Redis in &period;NET Core 入门:&lpar;2&rpar; String

    第1篇:https://www.cnblogs.com/cgzl/p/10294175.html‘ 本文简单介绍一下Redis的常用数据类型String. 基本上都是文档上的内容,所以比较无聊.... ...

  9. easyui的datagrid为何无法显示json数据

    因为easyui的datagrid要求数据JSON必须是如下格式:{"total":0,"rows":[]}其中total表示总的数据行数,rows是当前页的数 ...

  10. POJ 1958 Strange Towers of Hanoi

    Strange Towers of Hanoi Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3784 Accepted: 23 ...