bzoj3198
容斥原理+哈希表
恰好k个,那么上容斥原理,我们先2^6枚举相同的位置,用哈希表判断有多少个对应位置相同的元素,然后用容斥原理计算,似乎这里的容斥没有那么简单,详见这里 http://www.cnblogs.com/candy99/p/mobius.html, 要乘上组合数计算
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int N = , mod = ;
int n, k;
ll ans;
int c[][], a[N][];
namespace Hash_List {
int cnt, tot;
int h[N], bel[N];
struct List {
int nxt, id, cnt;
} e[N << ];
void ini() { ++cnt; }
bool same(int x, int y, int s) {
for(int i = ; i < ; ++i) if(s & ( << i) && a[x][i] != a[y][i]) return false;
return true;
}
int hash(int *a, int s) {
int h = ;
for(int i = ; i < ; ++i) if(s & ( << i)) h = ((h * % mod + a[i] % mod) % mod + mod) % mod;
return h;
}
int insert(int id, int s) {
int val = hash(a[id], s);
if(bel[val] != cnt) h[val] = , bel[val] = cnt; // 如果这个没有被标记过,那么就暴力查找,否则直接插入
for(int i = h[val]; i; i = e[i].nxt) if(same(e[i].id, id, s)) { ++e[i].cnt; return e[i].cnt - ; }
e[++tot] = (List) {h[val], id, }, h[val] = tot;
return ;
}
} using Hash_List :: insert; using Hash_List :: ini;
int one(int x) {
int ret = ;
while(x) ++ret, x &= (x - );
return ret;
}
int main()
{
scanf("%d%d", &n, &k);
c[][] = ;
for(int i = ; i <= ; ++i)
{
c[i][] = ;
for(int j = ; j <= i; ++j) c[i][j] = c[i - ][j] + c[i - ][j - ];
}
for(int i = ; i <= n; ++i)
for(int j = ; j < ; ++j) scanf("%d", &a[i][j]);
for(int i = ; i < ; ++i)
{
int t = one(i);
if(t < k) continue;
Hash_List :: ini();
for(int j = ; j <= n; ++j) ans += (((t - k) & ) ? - : ) * (ll)Hash_List :: insert(j, i) * (ll)c[t][k];
}
printf("%lld\n", ans);
return ;
}
bzoj3198的更多相关文章
- BZOJ3198 [Sdoi2013]spring 哈希 容斥原理
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ3198 题意概括 有n(1<=n<=100000)组数据,每组数据6个数. 现在问有几对 ...
- BZOJ3198[SDOI2013]SPRING
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 题 ...
- bzoj3198[Sdoi2013]spring 容斥+hash
3198: [Sdoi2013]spring Time Limit: 40 Sec Memory Limit: 256 MBSubmit: 1143 Solved: 366[Submit][Sta ...
- [BZOJ3622]已经没有什么好害怕的了(容斥DP)
给定两个数组a[n]与b[n](数全不相等),两两配对,求“a比b大”的数对比“b比a大”的数对个数多k的配对方案数. 据说做了这题就没什么题好害怕的了,但感觉实际上这是一个套路题,只是很难想到. 首 ...
随机推荐
- 数据库设计三范式(3NF)
问:当时你数据库是如何设计的? 答:当时是按照三范式规范设计的: 第一范式: 1:数据库的原子性,即保证数据库表的每一列都不可分割的 第二范式: 1:原子性,即保证数据库表的每一列都不可分割 2:表中 ...
- 针对JedisShardInfo中无法修改db的解决办法
package com.ldr.bean; import java.lang.reflect.Field; import redis.clients.jedis.JedisShardInfo; pub ...
- mysql获取子父级节点
获取所有子节点 DROP FUNCTION IF EXISTS `F_Co29_GetAllChildrenIdsOfTaskevent`;DELIMITER //CREATE FUNCTION `F ...
- 23. 客户默认选项(Default Customer Options)
Editing Email Templates Email Sender Contact Us
- hdoj-1856-More is better【并查集】
More is better Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 327680/102400 K (Java/Others) To ...
- BUPT复试专题—打牌(2011)
https://www.nowcoder.com/practice/82442ee76977479e8ab4b88dfadfca9f?tpId=67&tqId=29640&tPage= ...
- ubuntu compile php from source code
10down vote Assuming that you already have the OpenSSL libraries and header files (on rpm systems th ...
- Java类载入器(二)——自己定义类载入器
用户定制自己的ClassLoader能够实现以下的一些应用: 自己定义路径下查找自己定义的class类文件,或许我们须要的class文件并不总是在已经设置好的Classpath以下,那么我们必须想 ...
- 《python源代码剖析》笔记 Python的编译结果
本文为senlie原创.转载请保留此地址:http://blog.csdn.net/zhengsenlie 1.python的运行过程 1)对python源码进行编译.产生字节码 2)将编译结果交给p ...
- 网页JS简繁体字转换
用法:非得加上html头 utf-8编码 其它编码无测试 head 中引用 <script language='javascript' src='zh.js'></script> ...