Files
python/TangDou/LuoGuBook/P1990_DFS_JIYI.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

45 lines
1.7 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int MOD = 10000;
const int N = 1000010;
int f[N][3];
// 功能从后向前考查保证填充满的情况下计算在第x列放了count个小方块情况下有多少种办法
// 参数x:当前考查的是第x列
// 参数count:在x列放了几个位置范围是 0个与1个
int dfs(int x, int count) {
if (f[x][count] >= 0) return f[x][count];
if (x == 0) {
//第0列而且还放了一个这种情况是不可能发生的所以方案数为0
if (count == 1) return 0;
//第0列个数为0是正确的是有返回递归终点值的,值为1
return 1;
}
//出现了不可能发生的负值情况返回0
if (x < 0) return 0;
//结果变量
int ans = 0;
//如果x列没有小方格被放下
//情况1放一个竖的前面的可能性就是 dfs(x-1,0)
//情况2放两个横的前面的可能性就是 dfs(x-2,0)
//情况3放一个向左下开口的L或者放一个向左上开口的L,都会造成前面的剩余中产生第x-1列是一个小方格被放下的情况产生即dfs(x-1,1)
if (count == 0) ans = (ans + dfs(x - 1, 0) + dfs(x - 2, 0) + 2 * dfs(x - 1, 1)) % MOD;
//如果x列有一个小方格被放下
//情况1用一个L可以搞定就是 dfs(x-2,0)
//情况2用横着的放进来就会造成x-1列出现一个小方格的情况即 dfs(x-1,1)
if (count == 1) ans = (ans + dfs(x - 2, 0) + dfs(x - 1, 1)) % MOD;
return f[x][count] = ans;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < N; i++)
for (int j = 0; j < 3; j++)
f[i][j] = -1;
cout << dfs(n, 0);
}