HDU 1865

1sting

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3200    Accepted Submission(s): 1230

Problem 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

Author

z.jt

Source

2008杭电集训队选拔赛——热身赛

简单的动态规划

结果是斐波那契数列

分析:

假设长度为n的数字结果为f(n)

则f(n+1)有两种可能

1,合并后末尾依旧为1,则种类为f(n)

2,合并后末尾为2,则总类为f(n-1)

所以:f(n+1)=f(n)+f(n-1);

然后最大长度为200

直接用c++

long long 都存不下

看到java里有BigInteger类

打算来用Java玩玩

注意主类命名为Main

不能直接加 ,改为add

不能直接赋值,调用valueOf();

OK

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String args[])
    {
        Scanner input = new Scanner(System.in);
        BigInteger ans[] = new BigInteger[201];
        ans[0] = BigInteger.valueOf(1);;
        ans[1] = BigInteger.valueOf(1);;
        for(int i = 2;i<201;i++)
        {
              ans[i]=ans[i-1].add(ans[i-2]);
        }
        int T=input.nextInt();
        while(T!=0)
        {
            String str = input.next();
            int len = str.length();
            System.out.println(ans[len]);
            T--;
        }
    }

}
时间: 2024-10-18 09:18:59

HDU 1865的相关文章

hdu 1865 1sting

高精度 斐波那契数 #include<iostream> #include<cstring> #include<algorithm> using namespace std; const int L=110; string add(string a,string b)//只限两个非负整数相加 { string ans; int na[L]={0},nb[L]={0}; int la=a.size(),lb=b.size(); for(int i=0;i<la;i+

HDU 1865 1sting (递推、大数)

1sting Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7573    Accepted Submission(s): 2945 Problem Description You will be given a string which only contains ‘1’; You can merge two adjacent ‘1’

高精度题目列表

JAVA大数类练手 748 - Exponentiation Uva 424 Uva 10106 Uva 465 Uva 10494 POJ 2389 POJ 2756 HDU 1715 HDU 1047 HDU 1297 HDU 1002 HDU 1316 HDU 1865 HDU 1250 HDU 1042 HDU 1753 POJ 1220 HDU 2100 Uva 10023 Uva 10069 HDU 4762 Uva 10497 Uva 10844 HDU 4873 Uva 1478

Java大数练习第二弹

hdu1250 水题 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1250 import java.util.*; import java.math.BigInteger; public class Main{ public static void main(String[] args){ int a; Scanner in=new Scanner(System.in); while(in.hasNext()){ a=in.nextInt();

HDU分类

模拟题, 枚举 1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201 12

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

hdu 1250 Hat&#39;s Fibonacci

Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9677 Accepted Submission(s): 3210 Problem Description A Fibonacci sequence is calculated by adding the previous two members the seque

HDU——PKU题目分类

HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201

HDU 6203 ping ping ping [LCA,贪心,DFS序,BIT(树状数组)]

题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=6203] 题意 :给出一棵树,如果(a,b)路径上有坏点,那么(a,b)之间不联通,给出一些不联通的点对,然后判断最少有多少个坏点. 题解 :求每个点对的LCA,然后根据LCA的深度排序.从LCA最深的点对开始,如果a或者b点已经有点被标记了,那么continue,否者标记(a,b)LCA的子树每个顶点加1. #include<Bits/stdc++.h> using namespace std;