Problem Description
Here are 512 Wenchuan earthquake casualties in some of the disaster-stricken schools (painful!!) )
1, Sichuan Province Doujiangyan Poly Source Secondary School
Casualty situation: Number of students in distress (including disappearance) 320
A teaching building collapsed, the building 18 classes more than 420 students were buried, so far only less than 100 people were rescued.
2, Sichuan Province Mianyang Beichuan County Beichuan Middle School
Casualty situation: Number of students in distress (including missing) more than 1200 people
School classroom Damage is serious, six to seven storeys high of the main teaching building has collapsed only one person how high, the other two teaching buildings and dormitories have different degrees of collapse
3, Sichuan Province Mianyang Beichuan County Magariyama Primary School (Mianyang Demonstration Elementary School)
Casualty situation: Number of students killed (including missing) 698 persons
School is located in the suburb of Beichuan County one kilometer of the town, the number of teachers and students 1003 people, the earthquake caused the school a five-storey teaching building collapsed, only one layer left
4, Sichuan Province Mianyang Beichuan County Magariyama Kindergarten
Casualty situation: More than 500 teachers and students in school, only 20 people survived
School is located in Mianyang Beichuan County Qushan crisis Home Lane, Magariyama Kindergarten and preschool more than 500 students were landslides blast over 20 meters, teaching building like bamboo to fall, the overall outward 50 centimeters only by the naked eye can not make a judgment this is four floor ...
5. Mianyang Beichuan County, Sichuan Province Junior High School
Casualty situation: More than 240 teachers and students in school, only 20 people survived
The classroom is buried by the mudslide, the school has only one crooked flagpole and a bright flag ...
.....
Why do so many schools have heavy casualties? There may be a lot of things we should investigate. But for us, the most pressing task now is to rebuild the school so that the surviving students can enter the classroom early.
This is not, a donation from the community to build a hope that the primary school will be completed soon! The length of the school classroom is n meters, the width is 3 meters, now we have 2 kinds of floor tiles, the specifications are 1 meters x1 meters, 2 meters x2 meters, if you want to pave for the classroom, how many ways of laying?
Input
The input data first contains a positive integer c, which represents the C set of test cases, followed by the C row of data, each line containing a positive integer n (1<=n<=30), which represents the length of the classroom.
Output
For each set of test data, output the number of tiling schemes, one row per output.
Sample Input
2
2
3
Sample Output
3
5
Author
Lcy
Source
2008-06-18 "ACM Program Design" Final Exam--Sichuan refueling! China Refueling!
Ideas
Similar to the Domino shop, for the nth column, if it is paved to column N-1, then there is f[n-1]; if it is the N-2 column, then there is 2*f[n-2]
Recursive: f[i] = f[i-1] + f[i-2]*2
Initial conditions: f[1]=1,f[2]=3
Code
#include<bits/stdc++.h>using namespace std;__int64 f[31];int main(){ int c,k; cin >> c; f[1] = 1;f[2] = 3; for(int i=3;i<=40;i++) f[i] = f[i-1] + f[i-2]*2; for(int i=1;i<=c;i++) { cin >> k; cout << f[k] << endl; } return 0;}
Hdoj 2190. Mourning for 512 Wenchuan earthquake--rebuilding Hope Primary School