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的配对方案数. 据说做了这题就没什么题好害怕的了,但感觉实际上这是一个套路题,只是很难想到. 首 ...
随机推荐
- Spring基于Setter函数的依赖注入(DI)
以下内容引用自http://wiki.jikexueyuan.com/project/spring/dependency-injection/spring-setter-based-dependenc ...
- Android开发—智能家居系列】(二):用手机对WIFI模块进行配置
在实际开发中,我开发的这款APP是用来连接温控器,并对温控器进行控制的.有图为证,哈哈. 上一篇文章[Android开发—智能家居系列](一):智能家居原理的文末总结中写到: 手机APP控制智能温控器 ...
- GoogLeNet系列解读
GoogLeNet Incepetion V1 这是GoogLeNet的最早版本,出现在2014年的<Going deeper with convolutions>.之所以名为“GoogL ...
- [React] Persist Form Data in React and Formik with formik-persist
It can be incredibly frustrating to spend a few minutes filling out a form only to accidentally lose ...
- nginx+play framework +mongoDB+redis +mysql+LBS实战总结
nginx+play framework +mongoDB+redis +mysql+LBS实战总结(一) 使用这个样的组合结构已经很久了,主要是实现web-server,不是做网站,二是纯粹的数据服 ...
- MYSQL时间戳的处理
date为需要处理的参数(该参数是Unix 时间戳),可以是字段名,也可以直接是Unix 时间戳字符串 后面的 '%Y%m%d' 主要是将返回值格式化 例如: mysql>SELECT FROM ...
- java远程调用rmi入门实例
RMI是Java的一组拥护开发分布式应用程序的API.RMI使用Java语言接口定义了远程对象,它集合了Java序列化和Java远程方法协议(Java Remote Method Protocol). ...
- C#令人迷惑的DateTime:世界标准时间还是本地时间?
先来看一段代码: 复制内容到剪贴板程序代码 DateTime time = DateTime.Parse("2013-07-05 00:00:00");Console.WriteL ...
- 【读书笔记】iOS-GCD-用法
代码: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { dispatch_async(dispatch_get_gl ...
- Spark简单集群搭建
1. 上传spark-2.2.0-bin-hadoop2.7.tgz安装包到/home/dtouding目录下 2. 解压安装包到/bigdata/目录下,tar –zxvf spark-2.2.0- ...