Categories

HOJ 2014 Tiling ,有生以来第一次用JAVA过的题

心情那个激动啊~~~~

递推公式是:

a[0]=a[1]=1
a[i]=a[i-1]+2*a[i-2];

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.math.BigInteger;
import java.util.Scanner;
 
public class Main
{
	public static void main(String[] args)
	{
		BigInteger[] res = new BigInteger[255];
		res[0] = new BigInteger("1");
		res[1] = new BigInteger("1");
 
		for (int i = 2; i <= 250; i++)
		{
			res[i] = res[i - 2].add(res[i - 2]);
			res[i] = res[i].add(res[i - 1]);
		}
 
		Scanner in = new Scanner(System.in);
		while (in.hasNext())
		{
			int n = in.nextInt();
			System.out.println(res[n]);
		}
	}
}

2 comments to HOJ 2014 Tiling ,有生以来第一次用JAVA过的题

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

*