bzoj 3198 spring
要求恰好k个jordan筛法公式容斥就可以做了,判断的时候要hash挂链,不然被卡,忘了k=0了,不停wa;
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<(n);i++)
using namespace std;
const int N=100005;
const int mod=231733;
const int seed=13313;
const int C[7][7]={
{1,0,0,0,0,0,0},
{1,1,0,0,0,0,0},
{1,2,1,0,0,0,0},
{1,3,3,1,0,0,0},
{1,4,6,4,1,0,0},
{1,5,10,10,5,1,0},
{1,6,15,20,15,6,1},
};
typedef long long ll;
int head[mod],next[N],t[N][6],num[6],stk[N],top=0,n,k,data[N][6],tot=0,v[N];
ll ans=0,res=0;
int solve(int hash,int tmp){
for(int i=head[hash];i;i=next[i]){int f=1;
rep(j,0,tmp)if(data[i][j]!=num[j])f=0;
if(f)return ++v[i];
}
if(!head[hash])stk[++top]=hash;
next[++tot]=head[hash];head[hash]=tot;v[tot]=0;
rep(j,0,tmp)data[tot][j]=num[j];
return 0;
}
void clear(){
while(top)head[stk[top--]]=0;tot=0;
}
int main(){//freopen("in.in","r",stdin);
scanf("%d%d",&n,&k);
rep(i,0,n)rep(j,0,6)scanf("%d",&t[i][j]);
rep(s,0,(1<<6)){res=0;
int tmp=0;for(int i=s;i;i-=(i&-i))tmp++;
if(tmp<k)continue;
rep(i,0,n){int hash=0,tt=0;
rep(j,0,6){
if(s&(1<<j)){num[tt++]=t[i][j];hash=(int)(1ll*((1ll*hash*seed)%mod+t[i][j])%mod);
}
}
res+=solve(hash,tmp);
}
ans+=1ll*((tmp-k)&1 ? -1 : 1)*res*C[tmp][k];
clear();
}
printf("%lld",ans);
}