poj3254

状态压缩dp,数据弱,本程序时间效率O(12 * (2^24))

View Code
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define maxn 13
#define mod 100000000

int row, column;
int filter[maxn];
int f[maxn][1 << maxn];

void input()
{
    scanf("%d%d", &row, &column);
    for (int i = 1; i <= row; i++)
    {
        filter[i] = 0;
        for (int j = 0; j < column; j++)
        {
            int a;
            scanf("%d", &a);
            filter[i] = (filter[i] << 1) + a;
        }
    }
}

bool ok(int a, int b)
{
    if ((a & filter[b]) != a)
        return false;
    int x = 3;
    for (int i = 0; i < column - 1; i++)
    {
        if ((a & x) == x)
            return false;
        x = x << 1;
    }
    return true;
}

void work()
{
    memset(f, 0, sizeof(f));
    int n = 1 << column;
    f[0][0] = 1;
    for (int i = 1; i <= row; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (!ok(j, i))
                continue;
            for (int k = 0; k < n; k++)
                if ((k & j) == 0)
                    f[i][j] = (f[i][j] + f[i - 1][k]) % mod;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
        ans = (ans + f[row][i]) % mod;
    printf("%d\n", ans);
}

int main()
{
    //freopen("t.txt", "r", stdin);
    input();
    work();
    return 0;
}

转载于:https://www.cnblogs.com/rainydays/archive/2012/07/04/2576370.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值