https://nanti.jisuanke.com/t/31455

题意

给一个3*3的方格填入 1-9 九个数 
有些数是已知的,有些数是对方已知但我未知的,有些数是大家都未知的 
我要计算取得最大的对应值的期望

分析

题意有点难懂。

首先先枚举把剩下的数填入星号的情况(其实就是枚举星号的排列),这是对方所能知道的所有信息,然后对方将取八种决策中最优的情况,而因为井号的存在,所以其排列也会影响每种决策的分数,所以接着要枚举井号的排列情况,对于每种情况累加每个决策的分数,最后枚举完后,要除以井号排列数(期望=分数*概率),然后对方便会选择期望最高的决策,累加到最后答案中,枚举完所有星号的之后,需要将最后答案除以星号排列数

#include<bits/stdc++.h>
using namespace std;
double ans;
int cnt,tot;
bool vis[];
char s[][];
int p[],a[],tmp[];
int state[];
int S[][]={
,,,
,,,
,,,
,,,
,,,
,,,
,,,
,,
};
int score[]={,,,,,,,,,,,,,,
,,,,,,,,,,};
int fac[];
void work(){
vector<int> num;
for(int i=;i<;i++) state[i]=;
for(int i=;i<=;i++){
if(!vis[i]){
num.push_back(i);
}
} do{
int na=,nb=;
for(int i=;i<;i++){
for(int j=;j<;j++){
if(s[i][j]=='*') tmp[i*+j]=p[na++];
else if(s[i][j]=='#') tmp[i*+j]=num[nb++];
else tmp[i*+j]=s[i][j]-'';
}
}
for(int i=;i<;i++){
int sum=;
for(int j=;j<;j++){
sum+=tmp[S[i][j]];
}
state[i]+=score[sum];
}
}while(next_permutation(num.begin(),num.end()));
double res=;
for(int i=;i<;i++){
res=max(res,state[i]*1.0/fac[num.size()]);
}
ans+=res;
}
void dfs(int pos){
if(pos==tot){
cnt++;
work();
return;
}
for(int i=;i<=;i++){
if(!vis[i]){
vis[i]=true;
p[pos]=i;
dfs(pos+);
vis[i]=false;
}
}
} int main(){
fac[]=;
for(int i=;i<;i++) fac[i]=fac[i-]*i;
int T;
scanf("%d",&T);
while(T--){
memset(vis,false,sizeof(vis));
tot=;
for(int i=;i<;i++){
scanf("%s",s[i]);
int len = strlen(s[i]);
for(int j=;j<len;j++)
if(s[i][j]=='*') tot++;
else if(isdigit(s[i][j])) vis[s[i][j]-'']=true;
}
ans=cnt=;
dfs();
ans=ans/cnt;
printf("%.8f\n",ans);
}
return ;
}

ACM-ICPC 2018 徐州赛区网络预赛 C Cacti Lottery(期望+暴力)的更多相关文章

  1. ACM-ICPC 2018 徐州赛区网络预赛 C Cacti Lottery(暴力+期望)

    链接https://nanti.jisuanke.com/t/31455 思路 首先先枚举把剩下的数填入星号的情况(其实就是枚举星号的排列),这是对方所能知道的所有信息,然后对方将取八种决策中最优的情 ...

  2. ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)

    ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...

  3. ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer (最大生成树+LCA求节点距离)

    ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer J. Maze Designer After the long vacation, the maze designer ...

  4. 计蒜客 1460.Ryuji doesn't want to study-树状数组 or 线段树 (ACM-ICPC 2018 徐州赛区网络预赛 H)

    H.Ryuji doesn't want to study 27.34% 1000ms 262144K   Ryuji is not a good student, and he doesn't wa ...

  5. ACM-ICPC 2018 徐州赛区网络预赛 B(dp || 博弈(未完成)

    传送门 题面: In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl n ...

  6. ACM-ICPC 2018 徐州赛区网络预赛 B. BE, GE or NE

    In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named &qu ...

  7. ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study

    262144K   Ryuji is not a good student, and he doesn't want to study. But there are n books he should ...

  8. ACM-ICPC 2018 徐州赛区网络预赛 F. Features Track

    262144K   Morgana is learning computer vision, and he likes cats, too. One day he wants to find the ...

  9. ACM-ICPC 2018 徐州赛区网络预赛 I. Characters with Hash

    Mur loves hash algorithm, and he sometimes encrypt another one's name, and call him with that encryp ...

随机推荐

  1. LeetCode算法题-Maximum Average Subarray I(Java实现)

    这是悦乐书的第278次更新,第294篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第146题(顺位题号是643).给定由n个整数组成的数组,找到具有最大平均值的长度为k的 ...

  2. 关于模块安装及cmd安装pip3模块失败的 Read timed out.的补救方法

    自己在安装pip中的request模块时,安装到一半老是报错.我看了下报错的代码最后一句写的是 Read timed out. 就是读取超时,从网上查了一下,原因是由于中国的网比较慢,下载超时.需要在 ...

  3. Python开发【第三篇】基本数据类型

    整型 int __author__ = 'Tang' # 将字符串转换为数字 a = " b = int(a) # 前面是0的数转换,默认base按照十进制 a = " b = i ...

  4. Linux:Day13(下) GRUB

    GRUB(Boot Loader): grub:GRand Unified Bootloader grub 0.x:grub legacy grub 1.x:grub2 grub legacy: st ...

  5. vue 2.0 + ElementUI构建树形表格

    解决: 本来想在网上博客找一找解决方法,奈何百度到的结果都不尽人意,思维逻辑不清,步骤复杂,代码混乱,找了半天也没找到一个满意的,所以干脆就自己动手写一个 思路: table需要的数据是array,所 ...

  6. Python之find命令中的位置的算法

    find("s",a,b)    #s表示的是一个子序列,a表示的是检索的起始位置,b表示的是检索的终止位置,ab可有可无 test = "abcdefgh" ...

  7. Java instanceof运算符

    java 中的instanceof 运算符是用来在运行时指出对象是否是特定类的一个实例.instanceof通过返回一个布尔值来指出,这个对象是否是这个特定类或者是它的子类的一个实例. 用法: res ...

  8. hdu 3037——Saving Beans

    Saving Beans Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  9. ABP mysql

    SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator ...

  10. 如何去掉wordpress网站url里面的index.php(Apache服务器)

    在wordpress根目录新建.htaccess文件,并拷贝以下代码保存即可. <IfModule mod_rewrite.c> RewriteEngine On RewriteBase ...