zoukankan      html  css  js  c++  java
  • [bzoj3198] [Sdoi2013]spring

    Description

    img

    Input

    img

    Output

    img

    Sample Input

    3 3 
    1 2 3 4 5 6
    1 2 3 0 0 0
    0 0 0 4 5 6
    

    Sample Output

    2
    

    HINT

    img

    Dragonite修正数据

    题解

    前置知识:广义容斥原理

    由于是要求恰好k个满足的方案数,考虑容斥。

    设$alpha (x) $表示至少满足有x个相等的方案数,答案即为:

    [sum _{i=k}^n(-1)^{i-k}inom{i}{k}alpha (i) ]

    然后对于(alpha (x)),可以直接用(Hash\_Table)求。

    #pragma GCC optimize(3)
    #include<bits/stdc++.h>
    using namespace std;
     
    #define int long long
     
    void read(int &x) {
        x=0;int f=1;char ch=getchar();
        for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
        for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
    }
     
    void print(int x) {
        if(x<0) x=-x,putchar('-');
        if(!x) return ;print(x/10),putchar(x%10+'0');
    }
    void write(int x) {if(!x) putchar('0');else print(x);putchar('
    ');}
     
    #define maxn 2000050
     
    int binom(int n,int m) {
        int res=1;for(int i=1;i<=m;i++) res=res*(n-i+1);
        for(int i=1;i<=m;i++) res=res/i;return res;
    }
     
    int n,k,a[maxn][7];
     
    const int mod=1e6+19,base=10;
     
    struct Hash_Table {
        int head[mod+1],nxt[maxn],val[maxn][7],sum[maxn],tot;
        int insert(int p,int s) {
            int hs=0;
            for(int i=0;i<6;i++) if((s>>i)&1) hs=(hs*base+a[p][i+1])%mod;
            for(int i=head[hs];i;i=nxt[i]) {
                int cnt=0,bo=1;//write(hs);
                for(int j=1;j<=6;j++) if((s>>(j-1))&1) if(val[i][++cnt]!=a[p][j]) bo=0;
                if(bo) return sum[i]++;
            }
            nxt[++tot]=head[hs],head[hs]=tot;val[tot][0]=0;
            for(int i=1;i<=6;i++) if((s>>(i-1))&1) val[tot][++val[tot][0]]=a[p][i]; 
            sum[tot]++;return 0;
        }
        void clear() {
            tot=0;memset(head,0,sizeof head);
            memset(sum,0,sizeof sum);
        }
    }Hash;
     
    int calc(int s) {
        int l=__builtin_popcount(s),ans=0;
        if(l<k) return 0;
        Hash.clear();
        for(int i=1;i<=n;i++) ans+=Hash.insert(i,s);
        ans*=(((l-k)&1)?-1:1)*binom(l,k);
        //if(ans) printf("%d %d
    ",s,ans);
        return ans;
    }
     
    signed main() {
        read(n),read(k);
        for(int i=1;i<=n;i++) for(int j=1;j<=6;j++) read(a[i][j]);
        int ans=0;
        for(int i=0;i<(1<<6);i++) ans+=calc(i);
        write(ans);//Hash.debug();
        //cerr << (double) clock()/CLOCKS_PER_SEC << endl;
        return 0;
    }
    
  • 相关阅读:
    软件性能测试指标及其注意地方
    Oracle过程及函数的参数模式详解
    【转】Web Service单元测试工具实例介绍之SoapUI
    【转】如何读懂Oracle文档中的语法图
    浅谈session测试
    Cookie管理工具
    php 在linux 用file_exists() 函数判断 另外一台服务器映射过来的文件是否存在 总是返回false
    SecureCRT 设置字体跟颜色
    bootstrat 设置 select option 选项的值
    php 如何把中文写入json中 当json文件中还显示的是中文
  • 原文地址:https://www.cnblogs.com/hbyer/p/10030067.html
Copyright © 2011-2022 走看看