Tri Tiling
- 題目資訊
- 輸入
- 輸出
- 測驗樣例
- 來源
- 解答
- 想法
題目資訊
In how many ways can you tile a 3xn rectangle with 2x1 dominoes?
Here is a sample tiling of a 3x12 rectangle.
有多少種方法可以用2x1多米諾骨牌平鋪3xn矩形?
下面是3x12矩形的平鋪示例,

輸入
Input consists of several test cases followed by a line containing -1. Each test case is a line containing an integer 0 <= n <= 30.
輸入由幾個測驗用例組成,最后一行是一個-1,每個測驗用例都是一行,包含一個整數’0<=n<=30’,
輸出
For each test case, output one integer number giving the number of possible tilings.
對于每個測驗用例,輸出一個整數,給出可能的平鋪數,
測驗樣例
2
8
12
-1
3
153
2131
來源
Waterloo local 2005.09.24
解答
#include<iostream>
#define ll long long
using namespace std;
ll num[40];
int main()
{
//freopen("E://test.txt", "r", stdin);
ios::sync_with_stdio(false);
int n;
num[0] = 1;
num[1] = 0;
num[2] = 3;
for (int i = 3; i <= 35; i++)
{
if (i % 2 != 0)
{
num[i] = 0;
}
else
{
num[i] = num[i - 2] * 4 - num[i - 4];
}
}
while (cin >> n)
{
if (n == -1)
{
break;
}
cout << num[n] << endl;
}
return 0;
}
想法
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/260278.html
標籤:其他
上一篇:二十四、系結服務
下一篇:HPA monitoring cpu utilization fails for deployments which have init containers
