UVA_10359

    我们令f(n)表示有n列时的放置种数,那么我们不妨考虑左边第一个位置如何放置。实际上一共有三种情况,这样就可以得到f(n)=f(n-1)+2*f(n-2)。

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

public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
BigInteger[] f = new BigInteger[260];
f[0] = new BigInteger("1");
f[1] = new BigInteger("1");
for(int i = 2; i <= 250; i ++)
f[i] = f[i - 2].multiply(BigInteger.valueOf(2)).add(f[i - 1]);
while(cin.hasNext())
{
int n = cin.nextInt();
System.out.println(f[n]);
}
}
}


转载于:https://www.cnblogs.com/staginner/archive/2011/12/15/2289517.html

Logo

昇腾计算产业是基于昇腾系列(HUAWEI Ascend)处理器和基础软件构建的全栈 AI计算基础设施、行业应用及服务,https://devpress.csdn.net/organization/setting/general/146749包括昇腾系列处理器、系列硬件、CANN、AI计算框架、应用使能、开发工具链、管理运维工具、行业应用及服务等全产业链

更多推荐