2478: 【普及/提高-】【P1990】覆盖墙壁

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:1 解决:1

题目描述

你有一个长为 lns="http://www.w3.org/1998/Math/MathML"> 宽为 lns="http://www.w3.org/1998/Math/MathML">2 的墙壁,给你两种砖头:一个长 lns="http://www.w3.org/1998/Math/MathML">2 宽 lns="http://www.w3.org/1998/Math/MathML">1,另一个是 L 型覆盖 lns="http://www.w3.org/1998/Math/MathML">3 个单元的砖头。如下图:

0  0 0  00 

砖头可以旋转,两种砖头可以无限制提供。你的任务是计算用这两种来覆盖 lns="http://www.w3.org/1998/Math/MathML">×2 的墙壁的覆盖方法。例如一个 lns="http://www.w3.org/1998/Math/MathML">2×3 的墙可以有 lns="http://www.w3.org/1998/Math/MathML">5 种覆盖方法,如下:

012 002 011 001 011 012 112 022 011 001 

注意可以使用两种砖头混合起来覆盖,如 lns="http://www.w3.org/1998/Math/MathML">2×4 的墙可以这样覆盖:

0112 0012 

给定 lns="http://www.w3.org/1998/Math/MathML">,要求计算 lns="http://www.w3.org/1998/Math/MathML">2× 的墙壁的覆盖方法。由于结果很大,所以只要求输出最后 lns="http://www.w3.org/1998/Math/MathML">4 位。例如 lns="http://www.w3.org/1998/Math/MathML">2×13 的覆盖方法为 lns="http://www.w3.org/1998/Math/MathML">13465,只需输出 lns="http://www.w3.org/1998/Math/MathML">3465 即可。如果答案少于 lns="http://www.w3.org/1998/Math/MathML">4 位,就直接输出就可以,不用加前导 lns="http://www.w3.org/1998/Math/MathML">0,如 lns="http://www.w3.org/1998/Math/MathML">=3 时输出 lns="http://www.w3.org/1998/Math/MathML">5

输入

一个整数 lns="http://www.w3.org/1998/Math/MathML">,表示墙壁的长。

输出

输出覆盖方法的最后 lns="http://www.w3.org/1998/Math/MathML">4 位,如果不足 lns="http://www.w3.org/1998/Math/MathML">4 位就输出整个答案。

样例输入 复制

13

样例输出 复制

3465

提示

数据保证,lns="http://www.w3.org/1998/Math/MathML">11000000

#include<bits/stdc++.h>
using namespace std;
int dp[1000009],n;
int main()
{
	dp[1]=1;
	dp[2]=2;
	dp[3]=5;
	scanf("%d",&n);
	for(int i=4;i<=n;i++)
	{
		dp[i]=(dp[i-1]*2)%10000+dp[i-3]%10000;
		dp[i]%=10000;
	}
	printf("%d\n",dp[n]);
	return 0;	
}