zoukankan      html  css  js  c++  java
  • 骨牌铺方格(菲波那切数列)

    Problem Description
    在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数.
    例如n=3时,为2× 3方格,骨牌的铺放方案有三种,如下图:
     
    Input
    输入数据由多行组成,每行包含一个整数n,表示该测试实例的长方形方格的规格是2×n (0<n<=50)。
     
    Output
    对于每个测试实例,请输出铺放方案的总数,每个实例的输出占一行。
     
    Sample Input
    1 3 2
     
    Sample Output
    1 3 2
       
     1 #include<iostream>
     2 #include<iomanip>
     3 //#include<bits/stdc++.h>
     4 #include<cstdio>
     5 #include<cmath>
     6 #include<cstring>
     7 #include<algorithm>
     8 #include<sstream>
     9 #define PI  3.14159265358979
    10 #define LL long long
    11 #define  eps   0.00000001
    12 using namespace std;
    13 LL f[100];
    14 LL solve(LL x)
    15 {
    16     if(f[x]) return f[x];
    17     for(int i=4;i<=x;++i)
    18     {
    19         f[i]=f[i-1]+f[i-2];
    20     }
    21     return f[x];
    22 }
    23 int main()
    24 {
    25     int T;
    26     f[1]=1,f[2]=2,f[3]=3;
    27     while(cin>>T)
    28     {
    29         cout<<solve(T)<<endl;
    30     }
    31 
    32 }
    View Code
  • 相关阅读:
    《一个人的村庄》 ——刘亮程
    uva 11020
    Codeforces Round #190 (Div. 2) B. Ciel and Flowers
    hdu3308 线段树——区间合并
    线段树,区间更新
    vim 被墙
    ubuntu12.04 修复Grub2
    windows下mysql数据库忘记密码
    高性能的异步爬虫
    中间件
  • 原文地址:https://www.cnblogs.com/Auroras/p/10806184.html
Copyright © 2011-2022 走看看