UVA, 900 Brick Wall Patterns

题意:给你长度为2,宽度为1的砖,给你一定长度,求可以摆的砖的方式,看图更容易理解↓

思路:递推

1:1

2:1+1=2

3:1+2=3

4:2+3=5

5:3+5=8

……

满足规律:m[x]=m[x-1]+m[x-2]

 

代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 int n;
 5 #define MAXN 51
 6 long long m[MAXN];
 7 bool datecin()
 8 {
 9     if(scanf("%d",&n)!=EOF)
10     {
11         if(n==0)
12             return false;
13         return true;
14     }ac
15     return false;
16 }
17 
18 void datecal()
19 {
20 
21     m[0]=1,m[1]=1;
22     for(int i=2;i<MAXN;i++)
23         m[i]=m[i-1]+m[i-2];
24 }
25 
26 void showres()
27 {
28     printf("%lld\n",m[n]);
29 }
30 int main()
31 {
32     datecal();
33     while(datecin())
34     {
35         showres();
36     }
37     return 0;
38 }
View Code

 

转载于:https://www.cnblogs.com/byzsxloli/p/5397592.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值