题解 CF895C 【Square Subsets】
一道状压
注意到此题所以,我们只需要用一个桶统计每个数出现的个数就好了。
另外,打表发现
令
考虑
先从
显然,当选奇数个数
当选偶数个
让我们令当前的
选偶数个的情况有
这两个式子可以用二项式定理证明。
所以
如果
我们可以看到,任
这样我们就做完了。
注意开
code:
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define y0 pmt
#define y1 pmtpmt
#define x0 pmtQAQ
#define x1 pmtQwQ
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int > vi;
typedef pair<int ,int > pii;
typedef vector<pii> vii;
const int inf=0x3f3f3f3f, maxn=100007, mod=1e9+7;
const ll linf=0x3f3f3f3f3f3f3f3fLL;
const ll P=19260817;
const int p[]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67};//质数表
int n;
ll dp[2][1<<19];
ll cnt[75];
int I=0;
ll h[maxn];//2^k的表
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
int rt;
scanf("%d",&rt);
cnt[rt]++;
}
h[0]=1;
dp[0][0]=1;
for(int i=1;i<=n;i++)h[i]=(h[i-1]<<1)%mod;
for(int i=1;i<=70;i++){
if(cnt[i]==0)continue;
I^=1;//滚动数组
memset(dp[I],0,sizeof(dp[I]));//注意初始化
for(int mask=0 ; mask< (1<<19) ; mask++){
int mask1=mask;
int x=i;
for(int j=0;j<19&&x>=p[j];j++){
while(x%p[j]==0)x/=p[j],mask1^=(1<<j);
}
(dp[I][mask1]+=1LL*dp[I^1][mask]*h[cnt[i]-1]%mod)%=mod;
(dp[I][mask]+=1LL*dp[I^1][mask]*h[cnt[i]-1]%mod)%=mod;
}
}
printf("%I64d\n",(dp[I][0]-1+mod)%mod);
return 0;
}