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. poj 3469 Dual Core CPU 最小割

    题目链接 好裸的题....... 两个cpu分别作为源点和汇点, 每个cpu向元件连边, 权值为题目所给的两个值, 如果两个元件之间有关系, 就在这两个元件之间连边, 权值为消耗,这里的边应该是双向边 ...

  2. H3C交换配置PBR最佳实践

    简要说明 PBR算是比较常用的功能,需要我们去掌握一下 配置步骤简要 配置BFD 配置track 配置acl 配置policy-based-route 在接口上面应用policy-based-rout ...

  3. printf与scanf的返回值、注意点

    printf()的返回值为其输出字符串常量的字符数(注意字符数与字数的区别)注意计数针对所有的打印字符,包括空格和不可见的换行字符(不包括字符串的空字符). scanf()函数返回成功读入的项目的个数 ...

  4. Linux ---> 监控JVM工具

    Linux ---> 监控JVM工具shkingshking 发布时间: 2013/10/10 01:27 阅读: 2642 收藏: 26 点赞: 1 评论: 0 JDK内置工具使用 jps(J ...

  5. safari的调试工具

    safari的调试工具默认是没有打开的设置——>偏好设置——>高级———>在菜单栏中显示开发菜单

  6. HDU 5768 Lucky7(CRT+容斥原理)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5768 [题目大意] 求出一个区间内7的倍数中,对于每个ai取模不等于bi的数的个数. [题解] 首 ...

  7. 重拾CSS基础—开篇

    由来 从事软件行业一晃也5年有余,之间参与过若干个基于web的项目,所以javascript和Html基本已经相当熟悉,最近对于web前端开发比较关注,分析后发现CSS的确是自己的弱项,于是决定再加强 ...

  8. UI基础:UILabel.UIFont

    UILabel:标签 继承自UIView ,在UIView基础上扩充了显示文本的功能.(文本框) UILabel的使用步骤 1.创建控件 UILabel *aLabel=[[UILabel alloc ...

  9. wamp+thinkphp环境配置

    下载wamp并安装,启动wamp,会出现一个小图标,然后点击它——>Start All Services.我点击之后是橙色,不是绿色.绿色代表成功启动.我是IIS占用了80端口的缘故,所以我修改 ...

  10. this function has none of deterministic, no sql,or reads sql data in its declaration and binary logging is enabled

      原址:http://blog.chinaunix.net/uid-20639775-id-3031821.html   This function has none of DETERMINISTI ...