标签:水题 stdout ble 子集 ace algorithm iostream cst pen
题面: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 }
标签:水题 stdout ble 子集 ace algorithm iostream cst pen
原文地址:http://www.cnblogs.com/wfj2048/p/6915527.html