bzoj 3198: [Sdoi2013]spring (hash+容斥原理)
来源:互联网 发布:淘宝的心是怎么升级的 编辑:程序博客网 时间:2024/06/10 06:55
3198: [Sdoi2013]spring
Time Limit: 40 Sec Memory Limit: 256 MBSubmit: 947 Solved: 296
[Submit][Status][Discuss]
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
1 2 3 4 5 6
1 2 3 0 0 0
0 0 0 4 5 6
Sample Output
2
HINT
Dragonite修正数据
Source
Hash
题解:hash+容斥原理
刚开始hxy手残了,WA了,然后一脸惊恐的对着ATP说我不会被卡hash 了吧。。。。结果发现容斥系数貌似不太对啊,负号莫名多了。。。。。
将每个字符串hash,然后可以把k个不同,变成6-k个相同。就可以枚举哪些位置不同,然后消除掉hash中这些位的影响,计算hash值相同的数的个数。
我们在计算k的时候实际包含了0..k-1个位置不同的答案,所以需要容斥一下。
容斥的系数的绝对值就是组合数,至于正负,必然是一正一负交替排列啦。
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>#define N 200003#define p 2000001001#define ull unsigned long long #define LL long longusing namespace std;int n,m,ch[N][10],len,q[100];ull mi[N],hp[N],hash1[N];LL ans,base[10][10];void build(){base[0][0]=1;base[1][0]=-6; base[1][1]=1;base[2][0]=15; base[2][1]=-5; base[2][2]=1;base[3][0]=-20; base[3][1]=10; base[3][2]=-4; base[3][3]=1;base[4][0]=15; base[4][1]=-10; base[4][2]=6; base[4][3]=-3; base[4][4]=1;base[5][0]=-6; base[5][1]=5; base[5][2]=-4; base[5][3]=3; base[5][4]=-2; base[5][5]=1;base[6][0]=1; base[6][1]=-1; base[6][2]=1; base[6][3]=-1; base[6][4]=1; base[6][5]=-1; base[6][6]=1;}void solve(){for (int i=1;i<=n;i++) {hash1[i]=hp[i];for (int j=1;j<=len;j++) hash1[i]-=(ull)mi[q[j]]*ch[i][q[j]];}sort(hash1+1,hash1+n+1);LL sum=1; for (int i=2;i<=n;i++) if (hash1[i]==hash1[i-1]) { sum++; if (i==n) ans+=(LL)base[m][len]*sum*(sum-1)/2; } else { ans+=(LL)base[m][len]*sum*(sum-1)/2; sum=1; }}void dfs(int x,int now){if (x==len+1) {//for (int i=1;i<=len;i++) cout<<q[i]<<" ";//cout<<endl; //cout<<ans<<endl;solve();return;}for (int i=now;i<=6;i++){q[x]=i;dfs(x+1,i+1);}}int main(){freopen("a.in","r",stdin);//freopen("my.out","w",stdout);scanf("%d%d",&n,&m);mi[0]=1;for (int i=1;i<=8;i++) mi[i]=mi[i-1]*p;for (int i=1;i<=n;i++) for (int j=1;j<=6;j++) scanf("%d",&ch[i][j]),ch[i][j]++;for (int i=1;i<=n;i++) for (int j=1;j<=6;j++) hp[i]+=(ull)mi[j]*(ull)ch[i][j];build(); m=6-m;for (int i=0;i<=m;i++) {len=i;dfs(1,1);}printf("%I64d\n",ans);}
0 0
- bzoj 3198: [Sdoi2013]spring (hash+容斥原理)
- BZOJ 3198([Sdoi2013]spring-Hash判重+容斥原理)
- BZOJ 3198 Sdoi2013 spring Hash+容斥原理
- bzoj 3198: [Sdoi2013]spring hash&容斥原理
- bzoj 3198: [Sdoi2013]spring hash+容斥原理
- [BZOJ3198][Sdoi2013]spring(hash+容斥原理+组合数学)
- bzoj 3129: [Sdoi2013]方程(容斥原理+组合数学+数论)
- bzoj 3129 [Sdoi2013]方程 数论 容斥
- bzoj 3198: [Sdoi2013]spring 题解
- bzoj3198 [Sdoi2013]spring 哈希表+容斥
- 【bzoj】2190 - 仪仗队(容斥原理)
- bzoj 2393(容斥原理)
- bzoj 3622 容斥原理
- BZOJ 2005 容斥原理
- BZOJ 2045 容斥原理
- bzoj 1853 容斥原理
- BZOJ 2393 容斥原理
- bzoj 2393 & bzoj 1853 容斥原理
- Oracle Data Integrator 12cR1 (12.1.3.0.0)安装过程
- 符号表
- nginx负载均衡-5种策略
- 模拟下拉框选择对应菜单的内容
- HTML 不同空格的特性和表现
- bzoj 3198: [Sdoi2013]spring (hash+容斥原理)
- 阻止浏览器自身滑动事件 例如苹果手机的上拉下拉滑动
- Oracle Data Integrator学习资料
- javaQuery 获取当前元素(父元素,子元素,兄弟元素)
- 一个下载图标(Icon)非常棒的网站
- 文章标题STL中vector,Map,Set的实现原理
- Android studio 构建项目时一直卡在building gradle的完美解决方案
- 使用Repository Creation Utility创建档案库并连接
- 异常:Project configuration is not up-to-date with pom.xml解决方案