首页 > 其他 > 详细

D - 1sting(相当于斐波那契数列,用大数写)

时间:2015-11-18 22:42:06      阅读:336      评论:0      收藏:0      [点我收藏+]

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(相当于斐波那契数列,用大数写)

原文:http://www.cnblogs.com/rain-1/p/4975999.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!