码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-06-25 20:22:06      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:tchar   logs   names   lin   clu   return   ref   getch   getc   

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]彩灯 (线性基)

标签:tchar   logs   names   lin   clu   return   ref   getch   getc   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!