题解:
显然只需要知道某几位上是 1 1 的有多少个就可以容斥了,这个用枚举子集可以做到,但是不能AC。考虑一个错误的做法,对于某个状态 S S ,它出现了次,然后对于 S S 去掉某一位上的得到的 S′ S ′ , cnt[S′]+=cnt[S] c n t [ S ′ ] + = c n t [ S ] ,但是这样显然是错的,比如 A−>B A − > B , A−>C A − > C , B−>D B − > D , C−>D C − > D ,其中箭头表示转移,那么相当于 A A 转移了两次到。如何解决这个问题呢?其实从低位到高位转移就可以。
代码:
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=22;
const int Maxm=1000010;
const int inf=2147483647;
const int mod=1000000007;
int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return x*f;
}
int Pow(int x,int y)
{
if(!y)return 1;
if(y==1)return x;
int t=Pow(x,y>>1),re=(LL)t*t%mod;
if(y&1)re=(LL)re*x%mod;
return re;
}
bool mark[1<<Maxn];
int ans=0,n,m,k,a[Maxm],one[1<<Maxn],cnt[1<<Maxn];
int main()
{
memset(cnt,0,sizeof(cnt));
n=read(),m=read(),k=read();
for(int i=1;i<=m;i++)cnt[a[i]=read()]++;
one[0]=0;
for(int i=1;i<(1<<n);i++)one[i]=one[i>>1]+(i&1);
for(int i=0;i<n;i++)
for(int j=1;j<(1<<n);j++)
if((1<<i)&j)cnt[j-(1<<i)]+=cnt[j];
for(int i=1;i<(1<<n);i++)
{
if(one[i]&1)ans=(ans+Pow(cnt[i],k))%mod;
else ans=(ans-Pow(cnt[i],k)+mod)%mod;
}
printf("%d",ans);
}