成绩 | 10 | 开启时间 | 2018年03月1日 星期四 00:00 |
折扣 | 0.8 | 折扣时间 | 2018年12月30日 星期日 23:55 |
允许迟交 | 是 | 关闭时间 | 2018年12月30日 星期日 23:55 |
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 possible tilings.
Sample Input
2
8
12
-1
Sample Output
3
153
2131
Source
Waterloo local 2005.09.24
这题我没推出来,我想到了n为2时有三种情况,但往后就不知道怎样递推了。
算了,看了这么多题解,这篇讲的还挺好的,%一发。
http://blog.youkuaiyun.com/qq_33557479/article/details/50886653
#include<iostream>
using namespace std;
int x;
int dp[32];
void init()
{
dp[0] = 1;
dp[2] = 3;
for (int i = 4; i <= 30; i+=2)
{
dp[i] = 4 * dp[i - 2] - dp[i - 4];
}
}
int main()
{
init();
while (true)
{
cin >> x;
if (x == -1) break;
cout << dp[x] << endl;
}
return 0;
}