标题效果:

计算到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;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

ural 1932 The Secret of Identifier (容斥原理)的更多相关文章

  1. URAL 1932 The Secret of Identifier 题解

    http://acm.timus.ru/problem.aspx?space=1&num=1932 B - The Secret of Identifier Time Limit:1000MS ...

  2. URAL 1932 The Secret of Identifier(容斥)

    Description Davy Jones: You've been captain of the Black Pearl for 13 years. That was our agreement. ...

  3. ural 1932 The Secret of Identifier 容斥

    主题链接:点击打开链接 stl+容斥 #include <cstdio> #include <cstring> #include <algorithm> #incl ...

  4. URAL 1707. Hypnotoad&#39;s Secret(树阵)

    URAL 1707. Hypnotoad's Secret space=1&num=1707" target="_blank" style="" ...

  5. ural 1707. Hypnotoad's Secret(线段树)

    题目链接:ural 1707. Hypnotoad's Secret 题目大意:给定N和M,然后N组s0, t0, Δs, Δt, k,每组能够计算出k个星星的坐标:M组a0, b0, c0, d0, ...

  6. 容斥原理--计算并集的元素个数 URAL 1091

    在计数时,必须注意没有重复,没有遗漏.为了使重叠部分不被重复计算,人们研究出一种新的计数方法,这种方法的基本思想是:先不考虑重叠的情况,把包含于某内容中的所有对象的数目先计算出来,然后再把计数时重复计 ...

  7. 数学分析 + 容斥原理 - URAL 1907 Coffee and Buns

    Coffee and Buns Problem's Link: http://www.bnuoj.com/v3/contest_show.php?cid=6415#problem/H Mean: 给定 ...

  8. ural 1091. Tmutarakan Exams(容斥原理)

    1091. Tmutarakan Exams Time limit: 1.0 secondMemory limit: 64 MB University of New Tmutarakan trains ...

  9. URAL - 1091 Tmutarakan Exams (简单容斥原理)

    题意:K个不同数组成的集合,每个数都不超过S且它们的gcd>1.求这样的数的个数 分析:从2开始枚举gcd,但这样会发生重复.譬如,枚举gcd=2的集合个数和gcd=3的集合个数,枚举6的时候就 ...

随机推荐

  1. Jsoup 抓取和数据页 认识HTTP头

    推荐一本书:黑客攻防技术宝典.Web实战篇  :       顺便留下一个疑问:能否通过jsoup大量并发訪问web或者小型域名server,使其瘫痪?其有用jsoup熟悉的朋友能够用它解析url来干 ...

  2. Android正在使用Handler实现信息发布机制(一)

    上一篇文章,我们谈到了电话Handler的sendMessage方法,最后,我们将进入一个电话 sendMessageAtTime方法,例如下列: public boolean sendMessage ...

  3. 使用zzip和minizip解压缩文件

    #include <zzip/zzip.h> #include <zlib.h> #include <zip.h> #include <unzip.h> ...

  4. Web中的性能优化

    优化Web中的性能 简介 web的优化就是一场阻止http请求最终访问到数据库的战争.优化的方式就是加缓存,在各个节点加缓存. web请求的流程及节点 熟悉流程及节点,才能定位性能的问题.而且优化的顺 ...

  5. Windows Phone开发(16):样式和控件模板

    原文:Windows Phone开发(16):样式和控件模板 在前面资源一文中也提过样式,样式就如同我们做HTML页排版时常用到的CSS样式表,它是对于特定娄型的可视化元素,应该可以直接说是针对控件的 ...

  6. InputStreamReader 和 OutputStreamWriter类使用方法简单介绍,及演示。

    InputStreamReader 和 OutputStreamWriter类使用方法简单介绍. 一.InputStreamReader类 InputStreamReader 将字节流转换为字符流.是 ...

  7. NETSH WINSOCK RESET这个命令的意义和效果?

    简要地netsh winsock reset命令含义复位 Winsock 文件夹.一机多用的假设Winsock协议配置问题,那么问题会导致网络连接,我们需要使用netsh winsock reset命 ...

  8. HDU4144:Bacon's Cipher

    Problem Description Bacon's cipher or the Baconian cipher is a method of steganography (a method of ...

  9. ContentProvider的使用

    这方面的资料应该网上已经很多了,我在这里只是做简单的总结就行了. 如题:ContentProvider是android的内容提供器,可以为应用程序提供各种的数据,例如数据表,txt文件,xml文件等等 ...

  10. 基于Tkinter利用python实现颜色空间转换程序

    主要基于colorsys实现,例子是从hls转换到rgb,假设要换颜色空间非常easy仅仅须要改动一个函数 用到了Scale和Canvas组件 代码例如以下: from Tkinter import ...