Description

Input

Output

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

【思路】

容斥原理+Hash

恰有k个元素相同的对数=至少k+1个相同*C(k+1,k) - 至少k+2个相同*C(k+2,k) + ……

枚举状态i,如果是101表示至少1和3两个相同,把n个年份关于i构造一个hash,然后放入hash中统计。这里只是关于位是1的构造hash,其他位都忽略了,所以得到的是至少有多少个相同的数目。

学了个hash表的写法,新姿势get :)

【代码】

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; typedef unsigned long long ull;
typedef long long ll;
const int N = ;
const int B = ; namespace Hash_set
{
struct node {
node* nxt;
ull H; int v;
node(){}
node(node* _,ull __) :
nxt(_),H(__),v() {}
}*head[N],mempool[N],*C=mempool;
int vis[N],kase;
void init() {
kase++; C=mempool;
}
int& insert(ull st) {
int pos=st%;
if(vis[pos]!=kase) {
vis[pos]=kase; head[pos]=0x0;
}
for(node* p=head[pos];p;p=p->nxt)
if(p->H==st) return p->v;
head[pos]=new (C++) node(head[pos],st);
return head[pos]->v;
}
} int n,K,a[N][],C[][]; ll calc(int st)
{
using namespace Hash_set;
ll ans=;
init();
for(int i=;i<n;i++) {
ull hash=;
for(int j=;j<;j++)
if( st&(<<j) )
hash=(hash*B+a[i][j]);
int& val=insert(hash);
ans+=(val++);
}
return ans;
} void get_C()
{
for(int i=;i<=;i++) {
C[i][]=C[i][i]=;
for(int j=;j<i;j++)
C[i][j]=C[i-][j-]+C[i-][j];
}
} void read(int& x) {
char c=getchar(); int f=; x=;
while(!isdigit(c)){if(c=='-')f=-; c=getchar();}
while(isdigit(c)) x=x*+c-'',c=getchar();
} int main()
{
get_C();
read(n),read(K);
for(int i=;i<n;i++)
for(int j=;j<;j++) read(a[i][j]);
ll ans=;
for(int i=;i<;i++) {
int cnt=;
for(int j=;j<;j++)
if(i&(<<j)) cnt++;
if(cnt>=K) ans+=((cnt-K)&?-:)*calc(i)*C[cnt][K];
}
printf("%lld",ans);
return ;
}

最新文章

  1. 浅谈 facebook .net sdk 应用
  2. sublime text 3 package control
  3. css动画之波纹
  4. signed和unsigned
  5. 用户环境配置文件/etc/profile
  6. Java实现一致性Hash算法深入研究
  7. Jquery 概念性内容编辑器
  8. IceMx.Mvc 我的js MVC 框架 一、html代码的分离(视图)
  9. urllib2 源码小剖
  10. 自己动手编写IOC框架(二)
  11. Session的使用与Session共享问题
  12. Redis自学笔记:4.4进阶-消息通知
  13. New York is 3 hours ahead of California
  14. Ansible安装及OS规划
  15. 「破解」Xposed强
  16. lua常用方法收集
  17. 蓝牙协议分析(6)_BLE地址类型
  18. sql注入(转载)
  19. C++.运行时类型判断_测试代码
  20. BZOJ 3007 [SDOI2012]拯救小云公主 - 对偶图 + 并查集

热门文章

  1. ExtJS4.2学习(七)EditorGrid可编辑表格(转)
  2. Extjs-4.2.1(二)——使用Ext.define自定义类
  3. js数组反转
  4. Usermod 命令详解
  5. EasyUI datagrid 分页Json字符串格式
  6. Exploring the 7 Different Types of Data Stories
  7. sublime 配置
  8. QDialog之屏蔽Esc键(过滤,或者丢弃)
  9. P90、面试题11:数值的整数次方
  10. Android开发之全屏显示的两种方法