Tri Tiling
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2118 Accepted Submission(s): 1211
Problem Description In how many ways can you tile a 3xn rectangle with 2x1 dominoes? Here is a sample tiling of a 3x12 rectangle.
Input Input consists of several test cases followed by a line containing -1. Each test case is a line containing an integer 0 ≤ n ≤ 30.
Output For each test case, output one integer number giving the number of pZ??http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vc3NpYmxlIHRpbGluZ3MuCjxicj4KCiAKPGJyPgpTYW1wbGUgSW5wdXQKCjxwcmUgY2xhc3M9"brush:java;">2 8 12 -1
Sample Output
3 153 2131
Source University of Waterloo Local Contest 2005.09.24
Recommend Eddy | We have carefully selected several similar problems for you: 1133 1267 1207 1249 1284
转:::,如果n为奇数,必然无解。
代码:0MS
#include#include #include #include using namespace std ; #define M 31 int f [M ]={1 ,3 }; int main() { int i ,n ; for(i =2 ;i <M ;i ++) f [i ]=4 *f [i -1 ]-f [i -2 ]; while(cin >>n ) { if(n <0 ) break; if(n %2 ==0 ) cout <<f [n /2 ]<<endl ; else cout <<0 <<endl ; } return 0 ; }