poj 2506 Tiling(java解法)

题目链接:http://poj.org/problem?id=2506

本题用的java解的,因为涉及到大数问题,如果对java中的大数操作不熟悉请点这儿:链接

思路:地推公式f[i]=f[i-1]+2*f[i-2]

code:

import java.math.*;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		BigInteger a[] = new BigInteger[300];
		BigInteger b=new BigInteger("2");
		a[0]=BigInteger.valueOf(1);
		a[1]=BigInteger.valueOf(1);
		a[2]=BigInteger.valueOf(3);
		a[3]=BigInteger.valueOf(5);
		int n;

		for(int i=3;i<=255;i++)
		{
			a[i]=a[i-1].add(a[i-2].multiply(b));
		}
		while(cin.hasNext())
		{
			n=cin.nextInt();
			System.out.println(a[n]);
		}
	}
}

poj 2506 Tiling(java解法)

时间: 2024-11-10 13:45:54

poj 2506 Tiling(java解法)的相关文章

POJ 2506 -TILING

水题,一个小模拟,规律也好找 f3 = f1 * 2 + f2; #include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <algorithm> const int INF = 1e8; const int N = 100; #define ll long long using namespace std; int a[251][N]

[ACM] POJ 2506 Tiling (递推,大数)

Tiling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7487   Accepted: 3661 Description In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles? Here is a sample tiling of a 2x17 rectangle. Input Input is a sequence of lines,

POJ 2506 Tiling (递推 + 大数加法模拟 )

Tiling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7965   Accepted: 3866 Description In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles? Here is a sample tiling of a 2x17 rectangle. Input Input is a sequence of lines,

POJ 2506 Tiling(递推+大整数加法)

http://poj.org/problem?id=2506 题意: 思路:递推.a[i]=a[i-1]+2*a[i-2]. 计算的时候是大整数加法.错了好久,忘记考虑1了...晕倒. 1 #include<iostream> 2 #include<string> 3 #include<cstring> 4 #include<cstdio> 5 using namespace std; 6 7 int n; 8 char s[255][255]; 9 10

poj 2506 Tiling 递推

题目链接: http://poj.org/problem?id=2506 题目描述: 有2*1和2*2两种瓷片,问铺成2*n的图形有多少种方法? 解题思路: 利用递推思想,2*n可以由2*(n-1)的状态加上一块竖放2*1的瓷片转移得来,也可以由2*(n-2)的状态加上一块2*2的瓷片或者加上两块横放的2*1的瓷片转移得来. 可得出递推公式:dp[n] = dp[n-1] + dp[n-2]*2: ac秘诀: (1):从输出样例可以看出要用大数来表示,大概需要90位左右. (2):2*0不是零种

poj 2506 Tiling(高精度)

Description In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles? Here is a sample tiling of a 2x17 rectangle.  Input Input is a sequence of lines, each line containing an integer number 0 <= n <= 250. Output For each line of input, out

POJ 2506 Tiling (递推+高精度)

[题目链接]click here~~ [题目大意] In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles? Here is a sample tiling of a 2x17 rectangle. [解题思路]: (1)一个2*2的格子有三种填充方法: 两个横着放, 两个竖着放, 放一个2*2 (2)得出递推公式F[i]=F[i-1]+F[i-2]*2 然后就是套高精度模板了 代码; /* Author:HRW 递推+

[ACM] POJ 2506 Tiling (递归,睑板)

Tiling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7487   Accepted: 3661 Description In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles? Here is a sample tiling of a 2x17 rectangle. Input Input is a sequence of lines,

poj 2506 Tiling(大数+规律)

poj2506Tiling 此题规律:A[0]=1;A[1]=1;A[2]=3;--A[n]=A[n-1]+2*A[n-2];用大数来写,AC代码: #include<stdio.h> #include<string.h> #define MAX 300 int num[MAX][MAX]; int main() { int n; while(scanf("%d",&n)!=EOF) { memset(num,0,sizeof(num)); num[0]