2012: [Ceoi2010]Pin
来源:互联网 发布:套利定价知乎 编辑:程序博客网 时间:2024/05/21 09:01
2012: [Ceoi2010]Pin
Time Limit: 8 Sec Memory Limit: 259 MBSubmit: 266 Solved: 132
[Submit][Status][Discuss]
Description
给出N(2<=N<=50000)个长度为4的字符串,问有且仅有D(1<=D<=4)处不相同的字符串有几对。
Input
第1行: N,D 以下N行每行一个字符串
Output
一个数:有多少对有且仅有处不相同的字符串。
Sample Input
4 2
0000
a010
0202
a0e2
0000
a010
0202
a0e2
Sample Output
3
HINT
Source
鸣谢sachs
#include<iostream>#include<cstdio>#include<queue>#include<vector>#include<bitset>#include<algorithm>#include<cstring>#include<map>#include<stack>#include<set>#include<cmath>#include<ext/pb_ds/priority_queue.hpp>using namespace std;typedef long long LL;const int maxn = 5E4 + 50;const LL hash = 131;int n,d;LL ans,h[5],ha[maxn][5],g[5],f[5],C[5][5],sum[maxn];char ch[maxn][5];bool bo[5];void dfs(int x,int tot){if (x == 5) {if (tot) {map <LL,int> m; ans = 0;for (int i = 1; i <= n; i++) {LL now = 0;for (int j = 1; j <= 4; j++)if (bo[j]) now += ha[i][j];if (m[now] > 1) ans -= sum[m[now]-1];++m[now]; ans += sum[m[now]-1];}g[tot] += ans;}return;} bo[x] = 0; dfs(x + 1,tot);bo[x] = 1; dfs(x + 1,tot + 1);}int main(){#ifdef DMCfreopen("DMC.txt","r",stdin);#endifcin >> n >> d;for (LL i = 1; i < maxn; i++) sum[i] = sum[i-1] + i;for (int i = 1; i <= n; i++) scanf("%s",1+ch[i]);h[0] = 1; for (int i = 1; i <= 4; i++) h[i] = h[i-1]*hash;for (int i = 1; i <= n; i++)for (int j = 1; j <= 4; j++)ha[i][j] = 1LL*ch[i][j]*h[j];dfs(1,0);C[0][0] = 1;for (int i = 1; i <= 4; i++) {C[i][0] = 1;for (int j = 1; j <= i; j++) C[i][j] = C[i-1][j] + C[i-1][j-1];}f[4] = g[4];f[3] = g[3] - C[4][3]*f[4];f[2] = g[2] - C[3][2]*f[3] - C[4][2]*f[4];f[1] = g[1] - C[2][1]*f[2] - C[3][1]*f[3] - C[4][1]*f[4];f[0] = sum[n-1] - C[1][0]*f[1] - C[2][0]*f[2] - C[3][0]*f[3] - C[4][0]*f[4];cout << f[4 - d];return 0;}
0 0
- 2012: [Ceoi2010]Pin
- pin
- ceoi2010 切题记
- 【CEOI2010】【BZOJ2013】A huge tower
- 【bzoj2013】[Ceoi2010]A huge tower
- bzoj2013 [Ceoi2010]A huge tower
- 杂题 [Ceoi2010]A huge tower
- BZOJ2013 [Ceoi2010]A huge tower 乱搞
- Pin Connections
- PIN初探
- pin 回顾
- pin技巧
- PIN PUK1
- PIN学习
- PIN码
- MAC && PIN
- Pin 架构
- PIN BLOCK
- Redis集群(主从配置)
- mysql联接和子查询的使用
- 上架你的应用从申请开发者账号开始
- 10个经典的Java面试题集合
- ElasticSearch源码解析(五):排序(评分公式)
- 2012: [Ceoi2010]Pin
- Linux进程通信IPC--消息队列MessageQueue
- Git-SSH的配置使用【详细】
- 努力让自己变得更好.博客记录开发遇到的问题
- PAT甲级.1011. World Cup Betting (20)
- 哈希表和HashMap内部实现原理
- Linux进程通信IPC--共享内存SharedMemory
- 【Hibernate】简单应用实例
- 69道Spring面试题和答案