P3857 [TJOI2008]彩灯(线性基)

题目链接:https://www.luogu.org/problem/P3857

解题报告:

  给出一个序列,让你求出异或后有多少种可能的情况。

  将给的数插入到线性基中,最后答案即为$(1LL<<res)%2008$,res为线性基的种类数。

AC代码:

 1 #include<vector>
 2 #include<cstdio>
 3 #include<iostream>
 4 #include<cmath>
 5 #include<queue>
 6 #include<stack>
 7 #include<cmath>
 8 #include<algorithm>
 9 #define numm ch-48
10 #define pd putchar(' ')
11 #define pn putchar('
')
12 #define pb push_back
13 #define fi first
14 #define se second
15 #define fre1 freopen("1.txt","r",stdin)
16 #define fre2 freopen("2.txt","w",stdout)
17 using namespace std;
18 template <typename T>
19 void read(T &res) {
20     bool flag=false;char ch;
21     while(!isdigit(ch=getchar())) (ch=='-')&&(flag=true);
22     for(res=numm;isdigit(ch=getchar());res=(res<<1)+(res<<3)+numm);
23     flag&&(res=-res);
24 }
25 template <typename T>
26 void write(T x) {
27     if(x<0) putchar('-'),x=-x;
28     if(x>9) write(x/10);
29     putchar(x%10+'0');
30 }
31 const int maxn=20010;
32 const int N=60;
33 const int inf=0x3f3f3f3f;
34 const int INF=0x7fffffff;
35 typedef long long ll;
36 char s[60];
37 ll a[60],p[60];
38 int n,m;
39 ll get_ans() {
40     for(int i=1;i<=m;i++) {
41         for(int j=52;~j;j--)
42             if(a[i]&(1LL<<j)) {
43                 if(!p[j]) {
44                     p[j]=a[i];
45                     break;
46                 }
47                 a[i]^=p[j];
48             }
49     }
50     ll res=0;
51     for(int j=52;~j;j--)
52         if(p[j]) res++;
53     return (1LL<<res)%2008;
54 }
55 int main()
56 {
57 
58     read(n),read(m);
59     for(int i=1;i<=m;i++) {
60         scanf("%s",s);
61         for(int j=0;j<n;j++)
62             if(s[j]=='O') a[i]^=(1LL<<j);
63     }
64     write(get_ans());
65     return 0;
66 }
代码在这里!
原文地址:https://www.cnblogs.com/wuliking/p/11272348.html