1. 程式人生 > >uoj#300.【CTSC2017】吉夫特

uoj#300.【CTSC2017】吉夫特

com long long cnblogs oid using mes bin sin ans

題面:http://uoj.ac/problem/300

一道大水題,然而我並不知道$lucas$定理的推論。。

$\binom{n}{m}$為奇數的充要條件是$n&m=n$。那麽我們對於每個數,直接枚舉子集轉移就行了,復雜度是$O(3^{18})$,不會$T$。

 1 //It is made by wfj_2048~
 2 #include <algorithm>
 3 #include <iostream>
 4 #include <complex>
 5 #include <cstring>
 6 #include <cstdlib>
 7
#include <cstdio> 8 #include <vector> 9 #include <cmath> 10 #include <queue> 11 #include <stack> 12 #include <map> 13 #include <set> 14 #define rhl (1000000007) 15 #define inf (1<<30) 16 #define N (300010) 17 #define il inline 18 #define RG register 19
#define ll long long 20 #define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout) 21 22 using namespace std; 23 24 int f[N],a[N],b[N],n,ans; 25 26 il int gi(){ 27 RG int x=0,q=1; RG char ch=getchar(); 28 while ((ch<0 || ch>9) && ch!=-) ch=getchar();
29 if (ch==-) q=-1,ch=getchar(); 30 while (ch>=0 && ch<=9) x=x*10+ch-48,ch=getchar(); 31 return q*x; 32 } 33 34 il void work(){ 35 n=gi(); for (RG int i=1;i<=n;++i) a[i]=gi(),b[a[i]]=i; 36 for (RG int i=1;i<=n;++i){ 37 ans+=(f[i]++); if (ans>=rhl) ans-=rhl; 38 for (RG int s=a[i];s;s=(s-1)&a[i]) 39 if (b[s]>i){ f[b[s]]+=f[i]; if (f[b[s]]>=rhl) f[b[s]]-=rhl; } 40 } 41 printf("%d\n",ans); return; 42 } 43 44 int main(){ 45 File("gift"); 46 work(); 47 return 0; 48 }

uoj#300.【CTSC2017】吉夫特