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的配对方案数. 据说做了这题就没什么题好害怕的了,但感觉实际上这是一个套路题,只是很难想到. 首 ...
随机推荐
- Maven用项目模板生成项目
Archetype插件是Maven生成项目的项目模板,项目模板就是一个框,把文件夹这些定好,然后就可以在上开写具体逻辑等等. 最常用的命令: mvn archetype:generate 这个是生成一 ...
- [转] windows下Svn服务器之必须提交修改注释篇
1. 强制添加注释信息 找到Respositories目录下对应项目里的hooks目录下建立pre-commit.bat文件,复制如下内容: @echo off set SVNLOOK="C ...
- C#如何实现挂机锁
首先在主窗体中设置一个子窗体的实例,然后当点击挂机之后,隐藏当前窗体,同时显示子窗体. 把子窗体的背景窗体设置如下属性(主要是背景随便改成一个图片,然后FormBorderStyle改成None, ...
- Android Camera 拍照 三星BUG总结
Android Camera 三星BUG : 近期在Android项目中使用拍照功能 , 其他型号的手机执行成功了 只有在三星的相机上遇到了bug . BUG详细体现为 : (1) 摄像头拍照后图 ...
- uva 11488 - Hyper Prefix Sets(字典树)
H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...
- Objective C运行时(runtime)技术总结,好强大的runtime
前言: Objective C的runtime技术功能非常强大,能够在运行时获取并修改类的各种信息,包括获取方法列表.属性列表.变量列表,修改方法.属性,增加方法,属性等等,本文对相 ...
- java的多态以及重载,重写,前期绑定,后期绑定
多态的定义: 一个类实例的相同方法在不同情形有不同表现形式.多态机制使具有不同内部结构的对象可以共享相同的外部接口.这意味着,虽然针对不同对象的具体操作不同,但通过一个公共的类,它们(那些操作)可以通 ...
- Linux安装配置Redis CentOS 7 下安装Redis
Redis是一个高性能的,开源key-value型数据库.是构建高性能,可扩展的Web应用的完美解决方案,可以内存存储亦可持久化存储.因为要使用跨进程,跨服务级别的数据缓存,在对比多个方案后,决定使用 ...
- easyUI datagrid组件能否有display:none的隐藏效果
这个项目用了JQ easyUI datagrid 组件,我今天做了一个页面,页面有个div层,div里放了一个easyUI datagrid,页面初始化时div隐藏(display:none),通过点 ...
- Preference+PreferenceArray+DataModel
在Mahout中,用户的喜好被抽象为一个Preference,包含了userId,itemId和偏好值(user对item的偏好).Preference是一个接口,它有一个通用的实现是GenericP ...