[TJOI2008]彩灯 线性基

题面

题面

题解

题意:给定n个01串,求互相异或能凑出多少不同的01串。
线性基的基础应用。
对于线性基中的01串,如果我们取其中一些凑成一个新的01串,有一个重要的性质:任意2个不同方案凑出的01串也不相同。
因此我们只需要求出给定01串的线性基大小,然后求出有多少搭配方案即可,方案数即为\(2^{tot} - 1\)

#include<bits/stdc++.h>
using namespace std;
#define R register int
#define AC 55
#define LL long long
#define p 2008

int n, m, ans;
LL f[AC], maxn;
char s[AC];

inline int qpow(int x, int have)
{
    int rnt = 1;
    while(have)
    {
        if(have & 1) rnt = rnt * x % p;
        x = x * x % p, have >>= 1;
    }
    return rnt;
}

void work()
{
    scanf("%d%d", &n, &m), maxn = 1LL << 50;
    for(R i = 1; i <= m; i ++)
    {
        scanf("%s", s + 1);
        LL x = 0;
        for(R j = 1; j <= n; j ++) x = (x << 1) + (s[j] == 'O' ? 1 : 0);
        maxn = 1LL << 50;
        for(R j = 50; ~j; j --, maxn >>= 1)
        {
            if(!(x & maxn)) continue;
            if(!f[j]) {f[j] = x, ++ ans; break;}
            else x ^= f[j];
        }
    }
    printf("%d\n", qpow(2, ans));
}

int main()
{
//  freopen("in.in", "r", stdin);
    work();
//  fclose(stdin);
    return 0;
}

转载于:https://www.cnblogs.com/ww3113306/p/10354311.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值