P1990 覆盖墙壁
作者:互联网
// Problem: P1990 覆盖墙壁
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P1990
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// User: Pannnn
#include <bits/stdc++.h>
using namespace std;
template<class T>
void debugVector(const T &a) {
cout << "[ ";
for (size_t i = 0; i < a.size(); ++i) {
cout << a[i] << (i == a.size() - 1 ? " " : ", ");
}
cout << "]" << endl;
}
template<class T>
void debugMatrix2(const T &a) {
for (size_t i = 0; i < a.size(); ++i) {
debugVector(a[i]);
}
}
template<class T>
using matrix2 = vector<vector<T>>;
template<class T>
vector<vector<T>> getMatrix2(size_t n, size_t m, T init = T()) {
return vector<vector<T>>(n, vector<T>(m, init));
}
template<class T>
using matrix3 = vector<vector<vector<T>>>;
template<class T>
vector<vector<vector<T>>> getMatrix3(size_t x, size_t y, size_t z, T init = T()) {
return vector<vector<vector<T>>>(x, vector<vector<T>>(y, vector<T>(z, init)));
}
void printBigInteger(vector<int> a) {
for (size_t i = a.size() - 1; i >= 0; --i) {
cout << a[i];
}
}
vector<int> addBigInteger(vector<int> a, vector<int> b) {
vector<int> res;
int pre = 0;
for (size_t i = 0; i < a.size() || i < b.size() || pre; ++i) {
if (i < a.size()) pre += a[i];
if (i < b.size()) pre += b[i];
res.push_back(pre % 10);
pre /= 10;
}
return res;
}
/*
令f[n]表示铺满前2 * n的面积的墙的方案数
当放置的最后一列为2 * 1的砖块,以这种状态结尾的方案数为f[n - 1]
当放置的最后为2块1 * 2的砖块,以这种状态结尾的方案数为f[n - 2]
当放置的最后为L形砖块时
令g[n]表示铺满前2 * n的面积的墙,但第n + 1列的上方一块已经被铺上的方案数
方案数为2 * g[n - 2],第n - 1列此前铺1块,上下两种情况
对于g数组的维护g[n]
若其突起是由L形砖块造成,则以这种状态结尾的方案数为f[n - 1]
若其突起是一个1 * 2的砖块,此时其左侧仍是L形,以这种状态结尾的方案数是g[n - 1]
g[n] = f[n - 1] + g[n - 1];
f[n] = f[n - 1] + f[n - 2] + 2 * g[n - 2];
f[0] = 1;
g[0] = 0;
f[1] = g[1] = 1;
*/
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> f(n + 1);
vector<int> g(n + 1);
f[0] = 1;
f[1] = g[1] = 1;
for (int i = 2; i <= n; ++i) {
f[i] = f[i - 1] + f[i - 2] + 2 * g[i - 2];
g[i] = g[i - 1] + f[i - 1];
f[i] %= 10000;
g[i] %= 10000;
}
cout << f[n] << endl;
return 0;
}
标签:pre,覆盖,墙壁,P1990,init,vector,template,砖块,size 来源: https://www.cnblogs.com/pannnn/p/15908822.html