bzoj 3198 spring

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);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值