题意: 给定一个 3∗m 的矩形,现在你有两种砖块 1∗1,1∗2 ,有一些位置是不能放的,问有多少种放法使除了不能放的位置外全部放满。
分析 : 很经典的状压dp,只是加了一些不能放的位置,题目输入使浮点数,我们直接取整表示这个格子不能放。然后就是一些状态的转移。
以下是代码:
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define zero(x) (((x)>0?(x):-(x))<eps)
typedef pair<int, int>pii;
typedef pair<ll, ll>pll;
typedef pair<double, double>pdd;
const double eps = 1e-8;
const int maxn = 300010;
const int MAXM = 100005;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const double FINF = 1000000000000000.0;
const ll MOD = 100000007;
const double PI = acos(-1);
int state[30];
ll dp[30][10];
double x, y;
int main() {
int m, n;
scanf("%d%d", &m, &n);
memset(dp, 0, sizeof(dp));
for (int i = 0; i<n; ++i) {
scanf("%lf%lf", &x, &y);
state[(int)(x)] |= (1 << ((int)(y)));
}
for (int sta = 0; sta < 8; ++sta) {
if ((sta & state[0]) == 0) {
if (sta == 5)dp[0][sta] = 1;
else if (sta == 7)dp[0][sta] = 3;
else if (sta == 6 || sta == 3)dp[0][sta] = 2;
else dp[0][sta] = 1;
}
}
for (int i = 1; i < m; ++i) {
for (int s1 = 0; s1 < 8; ++s1) {
for (int s2 = 0; s2 < 8; ++s2) {
bool flag = 1;
for (int j = 0; j<3; ++j) {
if ((s1 & (1 << j)) == 0 && (s2 & (1 << j)) == 0 && (state[i - 1] & (1 << j)) == 0) {
flag = 0;
break;
}
}
if (!flag || (s2 & state[i]))continue;
int now = s2, res;
for (int j = 0; j < 3; ++j) {
if ((s1 & (1 << j)) == 0 && (state[i - 1] & (1 << j)) == 0)now ^= (1 << j);
}
if (now == 5)res = 1;
else if (now == 7)res = 3;
else if (now == 6 || now == 3)res = 2;
else res = 1;
dp[i][s2] += dp[i - 1][s1] * res;
//cout << i << " " << s2 << " " << dp[i][s2] << endl;
}
}
}
printf("%I64d\n", dp[m - 1][state[m - 1] ^ 7]);
}