UVA1224 LA3904 Tile Code铺砖问题
Posted 海岛Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA1224 LA3904 Tile Code铺砖问题相关的知识,希望对你有一定的参考价值。
The city of Songpa is now carrying out a project to build a bicycle transportation system called green Songpa. By the end of this year, citizens and visitors alike will be able to pick up and drop off bicycles throughout the city. Recently, it was decided to attach a number tag to each bicycle for management use. The bicycles will be under control of the citys traffic system.
The number tag contains a tile code of length n, which consists of 1×2, 2×1, and 2×2 tiles placed on a 2 × n rectangular plate in a way that every cell of the plate is covered by exactly one tile. The plate is divided into 2n cells of size 1×1. Of course, no two tiles are allowed to overlap each other. The 2 × 5 plate and a tile code of length 5 are shown in Figures 1 and 2, respectively. The code will always be read from left to right. However, there is no distinction between the top side and the bottom side of the code. The code may be turned upside down. The code shown in Figure 3 is essentially the same
code as in Figure 2.
Given a positive integer n, the project director Dr. Yang wants to know how many tile codes of length n there are, that is, the number of ways to place the three kinds of tiles into a 2 × n rectangular plate subject to the above conditions. Write a program that can help him.
Input
Your program is to read from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case is given in a single line, which contains a positive integer n, 3 ≤ n ≤ 30.
Output
Your program is to write to standard output. Print exactly one line for each test case. The line should contain the number of tile codes of length n.
Sample Input
2
3
4
Sample Output
3
8
问题链接:UVA1224 LA3904 Tile Code
问题简述:(略)
问题分析:数学的铺砖问题,需要找出递推式再进行数学计算。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* UVA1224 LA3904 Tile Code */
#include <bits/stdc++.h>
using namespace std;
const int N = 30;
int f[N + 1];
int main()
{
f[0] = 0;
f[1] = 1;
for (int i = 2; i <= N; i++)
f[i] = f[i - 1] + 2 * f[i - 2];
int t, n;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
int k = f[n];
if (n % 2 == 0) {
k += f[n / 2 + 1];
if (n / 2 % 2) k++;
} else {
k += f[n / 2];
if (n / 2 % 2) k--;
}
printf("%d\\n", k);
}
return 0;
}
以上是关于UVA1224 LA3904 Tile Code铺砖问题的主要内容,如果未能解决你的问题,请参考以下文章