Description

You will be given a string which only contains ‘1’; You can merge two adjacent ‘1’ to be ‘2’, or leave the ‘1’ there. Surly, you may get many different results. For example, given 1111 , you can get 1111, 121, 112,211,22. Now, your work is to find the total number of result you can get. 
 

Input

The first line is a number n refers to the number of test cases. Then n lines follows, each line has a string made up of ‘1’ . The maximum length of the sequence is 200. 
 

Output

The output contain n lines, each line output the number of result you can get . 
 

Sample Input

3 1 11 11111
 

Sample Output

1 2 8
 
 
简单题,用java中的大数写
注意类名Main
 
package test;
import java.util.Scanner;
import java.math.BigInteger;
public class Fib {
static BigInteger[] num = new BigInteger[205];
static String s;
public static void main(String[] args){
num[1] = new BigInteger("1");
num[2] = new BigInteger("2");
for(int i = 3; i <= 201; i++){
num[i] = num[i-1].add(num[i-2]);
//System.out.println(num[i]);
} Scanner in = new Scanner(System.in);
System.out.println("输入n");
int n = in.nextInt();
int flag = 1;
while((n--) != 0){
System.out.println("输入字符串");
if(flag == 1){
in.nextLine();
flag = 0;
}
s = in.nextLine();
int len = s.length();
System.out.println(num[len]);
}
}
}

D - 1sting(相当于斐波那契数列,用大数写)的更多相关文章

  1. HDU 1316 (斐波那契数列,大数相加,大数比较大小)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1316 Recall the definition of the Fibonacci numbers: ...

  2. 剑指Offer面试题:8.斐波那契数列

    一.题目:斐波那契数列 题目:写一个函数,输入n,求斐波那契(Fibonacci)数列的第n项.斐波那契数列的定义如下: 二.效率很低的解法 很多C/C++/C#/Java语言教科书在讲述递归函数的时 ...

  3. 剑指offer编程题Java实现——面试题9斐波那契数列

    题目:写一个函数,输入n,求斐波那契数列的第n项. package Solution; /** * 剑指offer面试题9:斐波那契数列 * 题目:写一个函数,输入n,求斐波那契数列的第n项. * 0 ...

  4. 《剑指offer》第十题(斐波那契数列)

    // 面试题:斐波那契数列 // 题目:写一个函数,输入n,求斐波那契(Fibonacci)数列的第n项. #include <iostream> using namespace std; ...

  5. 剑指Offer面试题:7.斐波那契数列

    一 题目:斐波那契数列 题目:写一个函数,输入n,求斐波那契(Fibonacci)数列的第n项.斐波那契数列的定义如下: 二 效率很低的解法 很多C/C++/C#/Java语言教科书在讲述递归函数的时 ...

  6. 剑指offer——面试题10:斐波那契数列

    个人答案: #include"iostream" #include"stdio.h" #include"string.h" using na ...

  7. C#求斐波那契数列第30项的值(递归和非递归)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. 斐波拉契数列加强版——时间复杂度O(1),空间复杂度O(1)

    对于斐波拉契经典问题,我们都非常熟悉,通过递推公式F(n) = F(n - ) + F(n - ),我们可以在线性时间内求出第n项F(n),现在考虑斐波拉契的加强版,我们要求的项数n的范围为int范围 ...

  9. js中的斐波那契数列法

    //斐波那契数列:1,2,3,5,8,13…… //从第3个起的第n个等于前两个之和 //解法1: var n1 = 1,n2 = 2; for(var i=3;i<101;i++){ var ...

随机推荐

  1. 转: angular编码风格指南

    After reading Google's AngularJS guidelines, I felt they were a little too incomplete and also guide ...

  2. crtmpserver初探

    前言       Adobe的FMS(Flash Media Server)是很好用.但对应着分级授权的是money和有限功能开放.商业的东西既然用不起,也阻碍了我们的技术进步,那就只能求助于开源社区 ...

  3. centos6.4-x86-64系统更新系统自带Apache Http Server

    系统自带Apache Http Server 版本比较老,有漏洞.现在对Apache Http Server进行升级.总体思路:先删除老的,再安装新的.详细步骤如下: 1 删除老版本 1.1 删除老A ...

  4. perl笔记

    更精确的空白字符串匹配 1.水平空白字符 Perl5.10之前,使用\s这种分类,不够精确,容易导致意料外的结果: Perl5.10中引入\h字符组,用来匹配任意水平空白字符(包括Unicode字符集 ...

  5. class类的sizeof计算

    class no_virtual { public: void fun1() const{} int fun2() const { return a; } private: int a; } clas ...

  6. ArrayList和LinkedList的各项操作性能比较

          如果用java编写程序,我们通常存储易变的数据集合时用到的数据结构往往是ArrayList,不过,在JDK中还存在另一个结构--LinkedList,只不过我们通常不用,原因在于性能问题, ...

  7. 使用jQuery创建模态窗口登陆效果

    日期:2013-8-22  来源:GBin1.com 隐藏模态窗口技术是一种很好的解决方案,用于处理不是特有必要出现在网页上的界面元素.社交网络可以使用模态窗口传达私人讯息以及只针对会员才能看 到的表 ...

  8. Android 调用相册 拍照 实现系统控件缩放 切割图片

    android 下如果做处理图片的软件 可以调用系统的控件 实现缩放切割图片 非常好的效果 今天写了一个demo分享给大家. package cn.m15.test; import java.io.B ...

  9. 注解方式实现Spring声明式事务管理

    1.编写实体类 public class Dept { private int deptId; private String deptName; public int getDeptId() { re ...

  10. github桌面软件使用教程

    github桌面软件使用教程 首先 要先安装 桌面版官网,或者百度搜github windows下载即可 可以再github网站上直接点击,把代码添加的桌面软件中 也可以再左上角添加项目,比如actu ...