首页 > 其他 > 详细

【题解】 luogu 3857 [TJOI2008]彩灯 (线性基)

时间:2018-06-25 19:28:42      阅读:192      评论:0      收藏:0      [点我收藏+]

luogu3857,懒得复制

Solution:

  • 裸的线性基,往里面添加数,记录添加个数\(sum\),快速幂输出\(2^{sum}\)即可

Code:

//It is coded by Ning_Mew on 5.30
#include<bits/stdc++.h>
#define LL long long
using namespace std;

const int maxn=70,MOD=2008;

int n,m;
LL s[maxn],x[maxn],ans=0;

LL read(){
  char ch=getchar();LL re=0;
  while(ch!='O'&&ch!='X')ch=getchar();
  while(ch=='O'||ch=='X'){
    if(ch=='O')re=((re<<1)^1);
    if(ch=='X')re=(re<<1);
    ch=getchar();
  }return re;
}
bool push(LL ss){
  for(int i=63;i>=0;i--){
    if((ss>>i)&1){
      if(!x[i]){x[i]=ss;return true;}
      else ss=(ss^x[i]);
    }
  }return false;
}
LL q_pow(LL x,LL t){
  LL re=1;
  while(t){
    if(t%2){re=(re*x%MOD);}
    x=x*x%MOD;
    t=t/2;
  }return re;
}
int main(){
  scanf("%d%d",&n,&m);
  for(int i=1;i<=m;i++){
    s[i]=read();//cout<<i<<' '<<s[i]<<endl;
  }
  for(int i=1;i<=m;i++){
    if(push(s[i]))ans++;
  }
  printf("%lld\n",q_pow(2,ans));
  return 0;
}

博主蒟蒻,随意转载。但必须附上原文链接:http://www.cnblogs.com/Ning-Mew/,否则你会终生找不到妹子!!!

【题解】 luogu 3857 [TJOI2008]彩灯 (线性基)

原文:https://www.cnblogs.com/Ning-Mew/p/9113552.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!