sdoi2013 spring(hash+容斥)
大体思路是先求出来\(f[i]\)代表有至少\(i\)个位置相同的点对数。
然后就已经没什么好害怕的了(跟BZOJ3622一样)
然后这个\(f[i\)]怎么求呢?
最无脑的方法就是枚举位置,然后\(hash\)表记一下每种情况出现多少次然后把\(\sum_{情况个数}{情况次数*(情况次数-1)}\)加到\(f[\)枚举的位置个数\(]\)。就行了。
发现这个方法复杂度足以通过此题。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define int long long
const int N=101000;
const int mod=23333;
const int p=19260817;
int cnt,head[25000];
struct edge{
int nxt,id,c;
}e[N];
int a[N][10],n,C[10][10],num,b[10],f[10],ans,mmp;
bool judge(int now,int x,int y){
for(int i=1;i<=num;i++)
if(a[x][b[i]]!=a[y][b[i]])return false;
return true;
}
void add(int u,int id){
cnt++;
e[cnt].nxt=head[u];
e[cnt].id=id;
e[cnt].c=1;
head[u]=cnt;
}
int ins(int now,int id,int x){
for(int i=head[x];i;i=e[i].nxt)
if(judge(now,e[i].id,id)){
e[i].c++;
return e[i].c-1;
}
add(x,id);
return 0;
}
int read(){
int sum=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){sum=sum*10+ch-'0';ch=getchar();}
return sum*f;
}
signed main(){
n=read();mmp=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]+C[i-1][j-1];
}
for(int i=0;i<(1<<6);i++){
num=0;
memset(head,0,sizeof(head));cnt=0;
for(int j=1;j<=6;j++)if(i&(1<<(j-1)))b[++num]=j;
for(int j=1;j<=n;j++){
int w=0;
for(int k=1;k<=num;k++)
w=(w*p%mod+a[j][b[k]]%mod)%mod;
f[num]+=ins(i,j,w);
}
}
int type=1;
for(int i=mmp;i<=6;i++){
ans+=type*C[i][mmp]*f[i];
type=-type;
}
printf("%lld",ans);
return 0;
}
sdoi2013 spring(hash+容斥)的更多相关文章
- [BZOJ 3198] [Sdoi2013] spring 【容斥 + Hash】
题目链接:BZOJ - 3198 题目分析 题目要求求出有多少对泉有恰好 k 个值相等. 我们用容斥来做. 枚举 2^6 种状态,某一位是 1 表示这一位相同,那么假设 1 的个数为 x . 答案就是 ...
- 【BZOJ3129】[SDOI2013]方程(容斥,拓展卢卡斯定理)
[BZOJ3129][SDOI2013]方程(容斥,拓展卢卡斯定理) 题面 BZOJ 洛谷 题解 因为答案是正整数,所先给每个位置都放一个就行了,然后\(A\)都要减一. 大于的限制和没有的区别不大, ...
- [BZOJ 3129] [Sdoi2013] 方程 【容斥+组合数取模+中国剩余定理】
题目链接:BZOJ - 3129 题目分析 使用隔板法的思想,如果没有任何限制条件,那么方案数就是 C(m - 1, n - 1). 如果有一个限制条件是 xi >= Ai ,那么我们就可以将 ...
- 洛谷$P$3301 $[SDOI2013]$方程 $exLucas$+容斥
正解:$exLucas$+容斥 解题报告: 传送门! 在做了一定的容斥的题之后再看到这种题自然而然就应该想到容斥,,,? 没错这题确实就是容斥,和这题有点儿像 注意下的是这里的大于和小于条件处理方式不 ...
- bzoj3198[Sdoi2013]spring 容斥+hash
3198: [Sdoi2013]spring Time Limit: 40 Sec Memory Limit: 256 MBSubmit: 1143 Solved: 366[Submit][Sta ...
- 3198: [Sdoi2013]spring【容斥原理+hash】
容斥是ans= 至少k位置相等对数C(k,k)-至少k+1位置相等对数C(k+1,k)+至少k+2位置相等对数*C(k+2,k) -- 然后对数的话2^6枚举状态然后用hash表统计即可 至于为什么要 ...
- [Sdoi2013] [bzoj 3198] spring (hash+容斥原理)
题目描述 给出nnn个666维坐标,求有多少对点对满足恰好mmm个位置相等 1<=n<=1051<=n<=10^51<=n<=105 0<=k<=60& ...
- [SDOI2013]泉(容斥)
/* 容斥加上哈希 首先我们可以2 ^ 6枚举相同情况, 然后对于这些确定的位置哈希一下统计方案数 这样我们就统计出了这些不同方案的情况, 然后容斥一下就好了 */ #include<cstdi ...
- codeforces 597div2 F. Daniel and Spring Cleaning(数位dp+二维容斥)
题目链接:https://codeforces.com/contest/1245/problem/F 题意:给定一个区间(L,R),a.b两个数都是属于区间内的数,求满足 a + b = a ^ b ...
随机推荐
- 使用Ansible安装部署nginx+php+mysql之安装mysql(3)
三.使用Ansible安装mysql 1.mysq.yaml文件 - hosts: clong remote_user: root gather_facts: no tasks: # 安装rpm包 - ...
- Problem 4
Problem 4 # Problem_4 """ A palindromic number reads the same both ways. The largest ...
- 实战:一、使用mongo做一个注册的小demo
思路:1.使用mongoose 进行 数据库的链接 2.使用Schema来进行传输字段的定义 3.安装koa-router进行数据处理4.安装koa-bodyparser 进行post数据交互5.解决 ...
- JS中的call()(转)
1.方法定义 call方法: 语法:call([thisObj[,arg1[, arg2[, [,.argN]]]]]) 定义:调用一个对象的一个方法,以另一个对象替换当前对象. 说明: call 方 ...
- 王立平--split字符串切割
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzQyNTUyNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- getColor()方法过时的替代方法
Android SDK 升級到 23 之後,getResource.getColor(R.color.color_name) 過時 使用新加入的方法 ContextCompat.getColor(co ...
- hashmap的put方法源码分析
put主源码如下: public V put(K key, V value) { if (key == null) return putForNullKey(value); int hash = ha ...
- 公布项目到NPM
修己安人,内圣外王 近期,在开发Node项目过程中遇到了须要类jQuery深拷贝对象的问题.去Github找了半天,并没有符合的,于是,自己决定写一个(mixin.js),然后推送到NPM(查看Npm ...
- 怎样避免使用Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK之后的黑屏问题
在自己的项目中.我须要使用Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK来開始新的activity同一时候移除之前全部的 ...
- 基于Socket的Winform例子
一.直接上效果图 二.Socket握手 三.服务端 Thread threadWatch = null;// 负责监听客户端的线程 Socket socketWatch = null;// 负责监听客 ...