ural 1932 The Secret of Identifier (容斥原理)
2015-08-13 09:19
351 查看
标题效果:
计算到n字符串。
精确到只是有一个不同的字符,两个不同的字符。三个不同的字符,四对不同的字符。
IDEAS:
枚举状态。
dp[i] [j] ...当前串取出 i 状态下的全部字符转化成十进制数为 j 的出现的次数。
这种话,就记录了全部串的子串的状态。
然后计数就得到了全部的状态。
然后我们要得到精确不同的,能够用补集的思想,假设要精确到三个不同样,意味着要精确到1 个是同样的。
注意的问题是
在最后要运用容斥去重。
计算到n字符串。
精确到只是有一个不同的字符,两个不同的字符。三个不同的字符,四对不同的字符。
IDEAS:
枚举状态。
dp[i] [j] ...当前串取出 i 状态下的全部字符转化成十进制数为 j 的出现的次数。
这种话,就记录了全部串的子串的状态。
然后计数就得到了全部的状态。
然后我们要得到精确不同的,能够用补集的思想,假设要精确到三个不同样,意味着要精确到1 个是同样的。
注意的问题是
在最后要运用容斥去重。
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; typedef long long ll; char str[6]; ll dp[16][1<<16]; int trans(char ch) { if(isdigit(ch))return ch-'0'; return ch-'a'+10; } int Count(int x) { int ret=0; while(x){ ret+=(x&1); x>>=1; } return ret; } ll tmp[5],ans[5]; int main() { int n; while(scanf("%d",&n)!=EOF) { int maxm=-1; memset(dp,0,sizeof dp); memset(tmp,0,sizeof tmp); for(int i=1;i<=n;i++) { scanf("%s",str); for(int s=1;s<16;s++) { int t=0; if(s&8) t += trans(str[0])*(1<<12); if(s&4) t += trans(str[1])*(1<<8); if(s&2) t += trans(str[2])*(1<<4); if(s&1) t += trans(str[3]); dp[s][t]++; maxm=max(t,maxm); } } for(int s=1;s<16;s++) { int x=Count(s); for(int i=0;i<=maxm;i++) { tmp[x]+=dp[s][i]*(dp[s][i]-1)/2; } } ans[1]=tmp[3]; ans[2]=tmp[2]-3*tmp[3]; ans[3]=tmp[1]-2*tmp[2]+3*tmp[3]; printf("%I64d %I64d %I64d %I64d\n",ans[1],ans[2],ans[3],(ll)n*(n-1)/2-ans[1]-ans[2]-ans[3]); } return 0; }
相关文章推荐
- iOS开发-oc(菜鸟笔记)
- pdf阅读器官网
- Git教程1——概论
- JVM项目调优文章-引发思考(精)
- 前进中不能迷失方向--Java程序员职业发展路线
- 微软面试100题2010年版全部答案集锦(含下载地址)
- Swift学习笔记之闭包
- 客户端webview持有的页面缓存,不会立即释放的问题解决
- Antenna Placement---poj3020(最大匹配)
- ruby on rail 微信企业号回调模式 url初次验证时 echostr的解密
- 字符序列 解题报告
- python字符编码
- Codeforces 300A Array
- Python 之 cPickle 实现 文件存取
- Android应用开发技巧之更方便的使用Sqlite
- 树链剖分模板+入门题 SPOJ - QTREE
- jvm调音
- C#绘制中国国旗的方法
- android studio f3怎么不跳转?
- 便宜真的没好货吗?戴尔闪存为存储经济性正名