/*
容斥加上哈希 首先我们可以2 ^ 6枚举相同情况, 然后对于这些确定的位置哈希一下统计方案数
这样我们就统计出了这些不同方案的情况, 然后容斥一下就好了 */
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
#define ll unsigned long long
#define M 101010
#define mmp make_pair
using namespace std;
int read()
{
int nm = 0, f = 1;
char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
return nm * f;
}
const int mod = 100007, base = 17171;
int n, k, a[M][7], c[7][7], cnt[131]; struct Mp
{
vector<pair<ll, int> > hs[M];
void init()
{
for(int i = 0; i < mod; i++) vector<pair<ll, int> >().swap(hs[i]);
} void insert(ll x)
{
int op = x % mod;
bool f = false;
for(int i = 0; i < hs[op].size(); i++)
{
if(x == hs[op][i].first)
{
hs[op][i].second++;
f = true;
break;
}
}
if(!f) hs[op].push_back(mmp(x, 1));
} ll calc()
{
ll ans = 0;
for(int i = 0; i < mod; i++)
{
for(int j = 0; j < hs[i].size(); j++)
{
int x = hs[i][j].second;
ans += 1ll * x * (x - 1) / 2;
}
}
return ans;
}
}mp; ll work(int x)
{
mp.init();
for(int i = 1; i <= n; i++)
{
ll v = 0;
for(int j = 1; j <= 6; j++)
{
v *= base;
if(x & (1 << (j - 1))) v += a[i][j] + 1;
}
mp.insert(v);
}
return mp.calc();
} int main()
{
n = read(), k = read();
for(int i = 1; i <= n; i++) for(int j = 1; j <= 6; j++) a[i][j] = read();
c[0][0] = 1;
for(int i = 1; i <= 6; i++)
{
c[i][0] = 1;
for(int j = 1; j <= i; j++) c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
}
for(int i = 1; i < 64; i++) cnt[i] = cnt[i >> 1] + (i & 1);
long long ans = 0;
for(int i = 0; i < 64; i++)
{
if(cnt[i] >= k)
{
long long t = work(i);
t = t * c[cnt[i]][k];
if((cnt[i] - k) & 1) ans -= t;
else ans += t;
}
}
cout << ans << "\n";
return 0;
}

[SDOI2013]泉(容斥)的更多相关文章

  1. bzoj3198[Sdoi2013]spring 容斥+hash

    3198: [Sdoi2013]spring Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 1143  Solved: 366[Submit][Sta ...

  2. bzoj 3202 [Sdoi2013]项链——容斥+置换+推式子

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3202 可见Zinn博客:https://www.cnblogs.com/Zinn/p/100 ...

  3. [BZOJ3622]已经没有什么好害怕的了(容斥DP)

    给定两个数组a[n]与b[n](数全不相等),两两配对,求“a比b大”的数对比“b比a大”的数对个数多k的配对方案数. 据说做了这题就没什么题好害怕的了,但感觉实际上这是一个套路题,只是很难想到. 首 ...

  4. [BZOJ 3198] [Sdoi2013] spring 【容斥 + Hash】

    题目链接:BZOJ - 3198 题目分析 题目要求求出有多少对泉有恰好 k 个值相等. 我们用容斥来做. 枚举 2^6 种状态,某一位是 1 表示这一位相同,那么假设 1 的个数为 x . 答案就是 ...

  5. 【BZOJ3129】[SDOI2013]方程(容斥,拓展卢卡斯定理)

    [BZOJ3129][SDOI2013]方程(容斥,拓展卢卡斯定理) 题面 BZOJ 洛谷 题解 因为答案是正整数,所先给每个位置都放一个就行了,然后\(A\)都要减一. 大于的限制和没有的区别不大, ...

  6. [BZOJ 3129] [Sdoi2013] 方程 【容斥+组合数取模+中国剩余定理】

    题目链接:BZOJ - 3129 题目分析 使用隔板法的思想,如果没有任何限制条件,那么方案数就是 C(m - 1, n - 1). 如果有一个限制条件是 xi >= Ai ,那么我们就可以将 ...

  7. 洛谷$P$3301 $[SDOI2013]$方程 $exLucas$+容斥

    正解:$exLucas$+容斥 解题报告: 传送门! 在做了一定的容斥的题之后再看到这种题自然而然就应该想到容斥,,,? 没错这题确实就是容斥,和这题有点儿像 注意下的是这里的大于和小于条件处理方式不 ...

  8. [SDOI2013]泉

    题目描述 作为光荣的济南泉历史研究小组中的一员,铭铭收集了历史上x个不同年份时不同泉区的水流指数,这个指数是一个小于. 2^30的非负整数.第i个年份时六个泉区的泉水流量指数分别为 A(i,l),A( ...

  9. POJ1091跳蚤(容斥 + 唯一分解 + 快速幂)

      题意:规定每次跳的单位 a1, a2, a3 …… , an, M,次数可以为b1, b2, b3 …… bn, bn + 1, 正好表示往左,负号表示往右, 求能否调到左边一位,即 a1* b1 ...

随机推荐

  1. mysql之 openark-kit online ddl

    MySQL工具集openark-kit (官方网站 http://code.openark.org/forge/openark-kit),内部包含很多小工具,在5.6之前用于实现online ddl操 ...

  2. supervisorctl 常用命令

    命令官方文档:http://supervisord.org/running.html#running-supervisorctl supervisorctl 常用命令: supervisorctl 常 ...

  3. antd 知识点

    表格实现:不管多少列,为列指定一个宽度,让表格在容器里可左右拖动 例子文件地址:https://github.com/cag2050/antd_mobx_demo/blob/master/src/co ...

  4. Laravel $request添加数据或数据修改

    laravel开发项目的时候,很多时候我们从$request里获取请求参数,今天在做项目的时候,遇到这样一个需求,就是请求参数到后台,后台需要根据判断重新给$request赋值,那如何去处理的 使用  ...

  5. 关于信号的延迟---verilog

    关于信号的延迟---verilog `timescale 1ns / 1ps ///////////////////////////////////////////////////////////// ...

  6. 基于selector的socket并发

    server: #!_*_coding:utf-8_*_ #__author__:"Alex huang" import selectors #selector模块集成了selec ...

  7. Azure PowerShell (13) 批量设置Azure ARM Network Security Group (NSG)

    <Windows Azure Platform 系列文章目录> 刚刚在帮助一个合作伙伴研究需求,他们的虚拟机全面的网络安全组(Network Security Group, NSG)会经常 ...

  8. php 安装mongo扩展(其他扩展同理)

    很多次安装mogo扩展不成功,总结出来,无非就是一个原因.对应的版本选择不正确 简单来说这篇文章就是来教你如何选择php对应的mongo.ll版本 查看phpinfo https://pecl.php ...

  9. apk重签名方法

    转载(http://www.51testing.com/?uid-115892-action-viewspace-itemid-223023) 1.      生成Android APK包签名证书 1 ...

  10. 峰Redis学习(10)Redis 集群(单机多节点集群和多机多节点集群)

    单机多节点集群:参考博客:http://blog.java1234.com/blog/articles/326.html 多机多节点集群:参考博客:http://blog.java1234.com/b ...