《洛谷P3857 [TJOI2008]彩灯》

可以发现,对于每种开关,都可以看成二进制位来转换成一个十进制的数。

那么,由于线性基里的元素构造出来是不会有重复的。

那么我们就是去插入线性基。然后对于每个线性基里的数都有选和不选的可能

所以ans = 1LL<<cnt。不要忘记取模

// Author: levil
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int N = 2e4+5;
const int M = 1e4;
const LL Mod = 2008;
#define rg register
#define pi acos(-1)
#define INF 1e18
#define CT0 cin.tie(0),cout.tie(0)
#define IO ios::sync_with_stdio(false)
#define dbg(ax) cout << "now this num is " << ax << endl;
namespace FASTIO{
    inline LL read(){
        LL x = 0,f = 1;char c = getchar();
        while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();}
        while(c >= '0' && c <= '9'){x = (x<<1)+(x<<3)+(c^48);c = getchar();}
        return x*f;
    }
    void print(int x){
        if(x < 0){x = -x;putchar('-');}
        if(x > 9) print(x/10);
        putchar(x%10+'0');
    }
}
using namespace FASTIO;
void FRE(){
/*freopen("data1.in","r",stdin);
freopen("data1.out","w",stdout);*/}

int n,m,cnt = 0;
LL p[55];
void insert(LL x)
{
    for(rg int i = 50;i >= 0;--i)
    {
        if(((x>>i)&1) == 0) continue;
        if(p[i] == 0)
        {
            p[i] = x;cnt++;
            return ;
        }
        else x ^= p[i];
    }
}
int main()
{
    n = read(),m = read();
    while(m--)
    {
        string s;cin >> s;
        int len = s.size();
        LL ma = 0;
        for(rg int i = 0;i < len;++i) if(s[i] == 'O') ma += (1LL<<i);
        insert(ma);
    }
    LL ans = (1LL<<cnt);
    printf("%lld
",ans%Mod);
    system("pause");
}
View Code
原文地址:https://www.cnblogs.com/zwjzwj/p/13567255.html