Gym 100825 G - Tray Bien[状压dp]

题意: 给定一个 3m 的矩形,现在你有两种砖块 11,12 ,有一些位置是不能放的,问有多少种放法使除了不能放的位置外全部放满。

分析 : 很经典的状压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]);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值