标题效果:

计算到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. ALV DataChange EVENT

    在CX项目中,根据需求,自定义一个表,维护供应商的银行账号信息,当输入供应商编号时,自动在供应商名称列里自动填写供应商名称,用到了ALV  DataChange 事件 ,下面是源代码: *&- ...

  2. php函数serialize()与unserialize() 数据序列化与反序列化

    php函数serialize()与unserialize()说明及案例.想要将已序列化的字符串变回 PHP 的值,可使用unserialize().serialize()可处理除了resource之外 ...

  3. windows phone 三种数据共享的方式(8)

    原文:windows phone 三种数据共享的方式(8) 本节实现的内容是数据共享,实现的效果描述:首先是建立两个页面,当页面MainPage通过事件导航到页面SecondPage是,我们需要将Ma ...

  4. altKey,ctrlKey,shiftKey

    <1> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>< ...

  5. 大页(huge pages) 三大系列 ---计算大页配置参数

    使用以下shell 脚本来计算大页配置参数,确保使用脚本实例之前的数据已经开始, 如果数据库的版本号11g,确认是否使用自己主动的内存管理(AMM) +++++++++++++++++++++++++ ...

  6. RMQ之ST算法

    #include <stdio.h> #include <string.h> ; int a[N]; ]; inline int min(const int &a, c ...

  7. 将ACCESS数据库迁移到SQLSERVER数据库

    原文:将ACCESS数据库迁移到SQLSERVER数据库 将ACCESS数据库迁移到SQLSERVER数据库 ACCESS2000文件 用ACCESS2007打开,并迁移到SQLSERVER2005里 ...

  8. JDK源码学习系列05----LinkedList

                                             JDK源码学习系列05----LinkedList 1.LinkedList简介 LinkedList是基于双向链表实 ...

  9. 72_leetcode_Construct Binary Tree from Preorder and Inorder Traversal

    Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that ...

  10. JavaScript模式读书笔记 文章3章 文字和构造

    1.对象字面量     -1.Javascript中所创建的自己定义对象在任务时候都是可变的.能够从一个空对象開始,依据须要添加函数.对象字面量模式能够使我们在创建对象的时候向其加入函数.       ...