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 }

时间: 2024-10-13 07:34:15

UVA, 900 Brick Wall Patterns的相关文章

[LeetCode] Brick Wall 砖头墙壁

There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. You want to draw a vertical line from the top to the bottom and cross the leastbricks. The brick wall

UVa 11587 - Brick Game

题目:背景:brick game是有N个木块,再给你一个若干整数构成的集合S,两个人轮流取木块: 取出的木块数是集合S中存在的任意数字,取走最后木块的人获胜,无法取则对方获胜. 题干:现在让你先取,给你一个你的结果序列串T,其中第k个字符代表有k个木块时你的结果: 可能赢就是T[k] = W:一定输就是T[k] = L. 问题:请你确定一个最小的集合,使得这个序列串T成立.(集合中元素为不超过20的正整数) 分析:状态压缩+dp验证.因为集合最多20个元素,利用20个位表示每个元素(1~20)的

Brick Wall

There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. You want to draw a vertical line from the top to the bottom and cross the least bricks. The brick wall

554. Brick Wall 砖墙

There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. You want to draw a vertical line from the top to the bottom and cross the least bricks. The brick wall

554. Brick Wall最少的穿墙个数

[抄题]: There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. You want to draw a vertical line from the top to the bottom and cross the least bricks. The bric

LeetCode 554: Brick Wall

The largest number could be n of walls. class Solution { public int leastBricks(List<List<Integer>> wall) { if (wall.size() == 0) { return 0; } int result = wall.size(); Map<Integer, Integer> sumMap = new HashMap<>(); for (List<

554. Brick Wall

class Solution { public: int leastBricks(vector<vector<int>>& wall) { unordered_map<int,int> m; for (int i = 0; i < wall.size(); i++) for (int j = 0, t = 0; j < wall[i].size() - 1; j++) { t += wall[i][j]; m[t]++; } int _max = 0

HDU 2354 Another Brick in the Wall(优先队列,bfs)

Problem Description: After years as a brick-layer, you've been called upon to analyze the structural integrity of various brick walls built by the Tetrad Corporation. Instead of using regular-sized bricks, the Tetrad Corporation seems overly fond of

HDOJ 1348 Wall 凸包

Wall Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4001    Accepted Submission(s): 1131 Problem Description Once upon a time there was a greedy King who ordered his chief Architect to build a