题解 P3773 【[CTSC2017]吉夫特】
安利blog
传送门
我好菜啊连卢卡斯都不会了
卢卡斯搞那一坨组合数:
后面那个
然后继续处理
我们发现,这不就是把
也就是说二进制下不存在某一位
问题就变成了求子序列的个数,满足每一项在二进制下是前一项的子集。
非常简短的代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#define maxn 250005
#define inf 0x3f3f3f3f
const int mod = 1e9 + 7;
using namespace std;
inline int read(){
int x=0,y=0;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')y=1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return y?-x:x;
}
int f[maxn];
int main(){
int n=read(),a,ans=0;
for(register int i=1;i<=n;++i){
a=read();
for(register int S=a-1&a;S;S=S-1&a)(f[S]+=f[a]+1)%=mod;
(ans+=f[a])%=mod;
}
printf("%d\n",ans);
}