意甲冠军:

n一定长度m串  隐藏的字符串相等的概率  然后,你猜怎么着玩家隐藏的字符串  的询问字符串的一个位置  再不断的知道一些位置后  游戏者就能够确定藏起来的串是什么  问  游戏者的期望步数

思路:

能够说是一道概率题  也能够说是期望题  总之感觉题目不错…

首先假设我们枚举藏起来的串是哪个(复杂度n)  然后利用状压去dp维护猜某些位的状态的概率  以及对于那个状态剩下哪些串是无法辨别的(复杂度m*2^m)  那么复杂度为 O(nm2^m) 这样就会TLE

接着思考  事实上问题不是出在状压的2^m上(它已经非常优秀了)  既然不去掉状压  那么辅助状态转移的m也扔不掉  我们仅仅能想方法避免那个n  使复杂度达到 O(m2^m)

然后我们来确定方案:

我们用状压的二进制数表示m个位置有哪些位置已经被揭示了  那么我们能够利用dp求出对于每一个状态的概率(或者称为从一位都不揭示到揭示到如今这样的状态的期望)  那么对于如今这样的状态  假设已经能够猜到藏起来的是哪个串  那么我们就不须要再猜了  否则至少要猜下一步  那么这个“下一步”对于整个游戏期望步数的贡献就为dp[状态]*1

如今问题就在  怎样推断这个状态是不是猜完了

事实上这个问题能够用dp打表出  对于已经猜了一些位置后  有哪些串是如今的状态分辨不出来的(代码中的f数组)

那么假设f为0  表示已经猜到了  假设不为0则里面至少有2个1存在  则对于当中的每一个1  假设藏起来的正是1相应的那个串  则还须要1步  那么这1步对答案的贡献就是刚才说的dp[]*1了

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<bitset>
using namespace std;
typedef long long LL;
#define N 55
#define M 25 int n, len;
char str[N][M];
LL f[(1 << 20) + 10], bin[N];
double ans[(1 << 20) + 10];
double res; int main() {
int i, j, k, c;
bin[0] = 1;
for (i = 1; i < N; i++)
bin[i] = (bin[i - 1] << 1);
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%s", str[i]);
len = strlen(str[1]);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (i != j) {
int same = 0;
for (k = 0; k < len; k++) {
if (str[i][k] == str[j][k])
same |= bin[k];
}
f[same] |= bin[j];
}
}
}
for (i = bin[len] - 1; i >= 0; i--) {
for (j = 0; j < len; j++) {
if (i & bin[j]) {
f[i ^ bin[j]] |= f[i];
}
}
}
ans[0] = 1;
for (i = 0; i < bin[len]; i++) {
for (c = j = 0; j < len; j++) {
if (i & bin[j])
c++;
}
for (j = 0; j < len; j++) {
if (!(i & bin[j]))
ans[i | bin[j]] += ans[i] / (len - c);
}
for (j = 0; j < n; j++) {
if (f[i] & bin[j])
res += ans[i];
}
}
printf("%.10f\n", res / n);
return 0;
}

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

CodeForces 482C Game with Strings的更多相关文章

  1. Codeforces 482C Game with Strings(dp+概率)

    题目链接:Codeforces 482C Game with Strings 题目大意:给定N个字符串,如今从中选定一个字符串为答案串,你不知道答案串是哪个.可是能够通过询问来确定, 每次询问一个位置 ...

  2. Codeforces 385B Bear and Strings

    题目链接:Codeforces 385B Bear and Strings 记录下每一个bear的起始位置和终止位置,然后扫一遍记录下来的结构体数组,过程中用一个变量记录上一个扫过的位置,用来去重. ...

  3. 【24.34%】【codeforces 560D】Equivalent Strings

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. CodeForces 682D Alyona and Strings (四维DP)

    Alyona and Strings 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/D Description After re ...

  5. codeforces 518A. Vitaly and Strings

    A. Vitaly and Strings time limit per test 1 second memory limit per test 256 megabytes input standar ...

  6. Codeforces 149 E. Martian Strings

    正反两遍扩展KMP,维护公共长度为L时.出如今最左边和最右边的位置. . .. 然后枚举推断... E. Martian Strings time limit per test 2 seconds m ...

  7. Codeforces 985 F - Isomorphic Strings

    F - Isomorphic Strings 思路:字符串hash 对于每一个字母单独hash 对于一段区间,求出每个字母的hash值,然后排序,如果能匹配上,就说明在这段区间存在字母间的一一映射 代 ...

  8. CodeForces - 616F:Expensive Strings (后缀自动机)

    You are given n strings ti. Each string has cost ci. Let's define the function of string , where ps, ...

  9. Codeforces 923 D. Picking Strings

    http://codeforces.com/contest/923/problem/D 题意: A-->BC , B-->AC , C-->AB , AAA-->empty 问 ...

随机推荐

  1. Java与C/C++有什么区别

    JDK包含JRE, 1-08: Helloworld: 01-08:classpath配置: 运行其它目录下的class文件: classpath一般不加分号,只找classpath下的文件: 后面加 ...

  2. 浅析ArrayList,LinkedList的执行效率

    以前见过很多文章说这两个东西,感觉自己还是没有深入理解,今天看了书明白一些,在此提出来和大家共同探讨: 面试的时候(基础)一般会问你使用过LinkedList或者ArrayList没有,简单的回答有或 ...

  3. auto_ptr and scoped_ptr

    #include "boost/scoped_ptr.hpp" #include <iostream> #include <memory>//contain ...

  4. 经典回忆Effective C++ 1

    c++ 联邦语言: typedef { unit C; unit Object-Oriented C++; unit Template C++; unit STL; }; notice: C++高效编 ...

  5. android中用get和post方式向服务器提交请求

    通过get和post方式向服务器发送请求首先说一下get和post的区别get请求方式是将提交的参数拼接在url地址后面,例如http://www.baidu.com/index.jsp?num=23 ...

  6. java文件创建、删除、读取、写入操作大全

    一.获得控制台用户输入的信息 public String getInputMessage() throws IOException...{ System.out.println("请输入您的 ...

  7. Mysql经常使用命令

    1.导出整个数据库 mysqldump -u username -p --default-character-set=latin1 数据库名 > 导出的文件名称(数据库默认编码是latin1) ...

  8. NET通用平台

    NET通用平台.通用权限.易扩展.多语言.多平台架构框架 先拿出我半前年前平台的设计初稿,经过半年的努力我已经完成了该设计稿的所有功能.并且理念已经远远超出该设计稿. 下面是一些博友对我贴子的评价: ...

  9. Java虚拟机几个命令行参数说明

    一.运行class文件 执行带main方法的class文件,Java虚拟机命令参数行为: java <CLASS文件名> 注意:CLASS文件名不要带文件后缀.class 例如: java ...

  10. iOS Dev (59) 高度自适应的UITextView

    iOS Dev (59) 高度自适应的UITextView 作者:阿锐 地址:http://blog.csdn.net/prevention - 例如以下 _inputTextView 为一个 UIT ...