# 覆盖墙壁

## 题目描述

0 0
0 00


012 002 011 001 011
012 112 022 011 001


0112
0012


## 输入输出样例

### 输入#1

13


### 输出#1

3465


# 分析

$f_i$$2\times i$尺寸墙壁的恰好覆盖方法。我们规定，$f_0 = 1$！！

0000
0000


0001
0001


0011
0022


0001
0011


0011
0001


0221
0211


0211
0221


0221
0011


$\begin{cases} f_n = f_{n - 1} + f_{n - 2} + 2 \times g_{n - 2} \\ g_n = f_{n - 1} + g_{n - 1} \end{cases}$

$g_n$的递推式。

$g_n = f_{n - 1} + g_{n - 1}\\ g_n = f_{n - 1} + f_{n - 2} + g_{n - 2}\\ g_n = f_{n - 1} + f_{n - 2} + f_{n - 3} + \ldots + f_1 + f_0\\ g_n = \sum_{i = 0} ^ {n - 1}f_i = \sum_{i = 1} ^ {n - 1} + 1$

$f_n = f_{n - 1} + f_{n - 2} + 2 \times \sum_{i = 1} ^ {n - 3}f_i + 2$

$f_{n - 1} = f_{n - 2} + f_{n - 3} + 2\times \sum_{i = 1} ^ {n - 4}f_i + 2$

$f_n = f_{n - 1} + f_{n - 2} + 2 \times \sum_{i = 1} ^ {n - 3}f_i + 2 \\ f_{n - 1} = f_{n - 2} + f_{n - 3} + 2\times \sum_{i = 1} ^ {n - 4}f_i + 2$

$f_n - f_{n - 1} = f_{n - 1} + f_{n - 2} + 2 \times \sum_{i = 1} ^ {n - 3}f_i + 2 - (f_{n - 2} + f_{n - 3} + 2\times \sum_{i = 1} ^ {n - 4}f_i + 2)$

$f_n - f_{n - 1} = f_{n - 1} + f_{n - 3}$

$f_n = 2 \times f_{n - 1} + f_{n - 3}$

$f_1 = 1\\ f_2 = 2\\ f_3 = 5$

# 代码

/*
* @Author: crab-in-the-northeast
* @Date: 2020-04-14 22:11:54
*/
#include <iostream>
#include <cstdio>

const int maxn = 1000005;
const int mod = 10000;
int dp[maxn] = {0, 1, 2, 5};

int main() {
int n;
std :: cin >> n;
if(n <= 3) {
std :: cout << dp[n] << std :: endl;
return 0;
}
for(int i = 4; i <= n; i++)
dp[i] = (dp[i - 1] * 2 % mod + dp[i - 3] % mod) % mod;
std :: cout << dp[n] << std :: endl;
return 0;
}


# 评测结果

AC 100：R32801187

posted @ 2020-04-15 15:21  东北小蟹蟹  阅读(260)  评论(0编辑  收藏  举报