1sting
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5933 Accepted Submission(s): 2271
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
import java.math.BigDecimal;
import java.util.Scanner;
class Main {
static BigDecimal[] dp=new BigDecimal[201];
public static void main(String[] args) {
da();
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
String str=sc.next();
System.out.println(dp[str.length()]);
}
}
public static void da(){
dp[1]=new BigDecimal("1");
dp[2]=new BigDecimal("2");
for(int i=3;i<dp.length;i++){
dp[i]=dp[i-1].add(dp[i-2] );
}
}
}
A == B ?
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 104100 Accepted Submission(s): 16558
Problem Description
Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".
Input
each test case contains two numbers A and B.
Output
for each case, if A is equal to B, you should print "YES", or print "NO".
Sample Input
1 2
2 2
3 3
4 3
Sample Output
import java.math.BigDecimal;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
BigDecimal a=sc.nextBigDecimal();
BigDecimal b=sc.nextBigDecimal();
if(a.compareTo(b)==0){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
}
Problem B
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 862 Accepted Submission(s): 348
1
3
5
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;
class Main {
static BigInteger dp[]=new BigInteger[205];
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
dp();
while(sc.hasNext()){
int n=sc.nextInt();
System.out.println(dp[n]);
}
}
public static void dp(){
dp[1]= new BigInteger("1");
dp[2]=new BigInteger("2");
for(int i=3;i<200;i++){
dp[i]=dp[i-1].add(dp[i-2]);
}
}
}