1023: Pong’s Birds

时间限制: 1 Sec  内存限制: 128 MB
提交: 94  解决: 21
[提交][状态][讨论版]

题目描述

In order to train his birds, Pong is holding a competition for them. (He have birds, does he?) He have 2n birds,
so he want to hold elimination series. Literally, if n = 2 and he has 4 birds identified as 1,2,3,4, he would first hold competition for 1 and 2, 3 and 4, the one fails would be eliminated and then he holds competition for the winners. 
According to his long observation, for each pair of birds he knows the probability to win for each bird, and he want to know the probability of each bird to be the final winner.

输入

For the first row there is an integer T(T ≤ 100), which is the number of test cases.
For each case , first row is an integer n(1 ≤ n ≤ 7), for the next 2n rows , each row has 2n real numbers as the probability to win for the i-th when competed to j-th bird. It is promised that for each i, j p[i][j] + p[j][i] = 1 and p[i][i] = 0;

输出

For each case you should output a line with 2n real numbers, which is the probability of i-th bird be the final winner. Rounded to 3 decimal places.
Make sure to output a space character after each number, to prevent the Presentation Error.

样例输入

1
1
0 0.5
0.5 0

样例输出

0.500 0.500

提示

求队伍夺冠概率,画图找下规律递推,

 #include <bits/stdc++.h>
using namespace std; const int MAXN = ( << ) + ;
double p[MAXN][MAXN];
double dp[][MAXN];//dp[i][j]表示第i轮j队伍出线概率 int main()
{
int t;
int n;
int n2;
int i, j, k;
int grp;
for (j = ; j < MAXN; ++j) {
dp[][j] = ;
}
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
n2 = << n;
for (i = ; i < n2; ++i) {
for (j = ; j < n2; ++j) {
scanf("%lf", &p[i][j]);
}
} for (i = ; i <= n; ++i) {
for (j = ; j < n2; ++j) {
grp = j / ( << (i - ));//
grp ^= ;//奇偶互换
dp[i][j] = ;
for (k = grp << (i - ); k < ((grp + ) << (i - )); ++k) {
dp[i][j] += dp[i - ][j] * dp[i - ][k] * p[j][k];
}
}
} for (i = ; i < n2 - ; ++i) {
printf("%.3lf ", dp[n][i]);
}
printf("%.3lf\n", dp[n][n2 - ]);
}
return ;
}

记忆化搜索

 #include <bits/stdc++.h>
using namespace std; const int MAXN = ( << ) + ;
double p[MAXN][MAXN];
double dp[][MAXN];//dp[i][j]表示第i轮j队伍出线概率 double dfs(int i, int j)
{
if (i == ) {
return ;
}
if (dp[i][j] >= ) {
//printf("%lf\n", dp[i][j]);
return dp[i][j];
}
int k;
int grp;
grp = j / ( << (i - ));//
grp ^= ;//奇偶互换
dp[i][j] = ;
for (k = grp << (i - ); k < ((grp + ) << (i - )); ++k) {
dp[i][j] += dfs(i - , j) * dfs(i - , k) * p[j][k];
}
return dp[i][j];
} int main()
{
int t;
int n;
int n2;
int i, j, k;
int grp;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
n2 = << n;
for (i = ; i < n2; ++i) {
for (j = ; j < n2; ++j) {
scanf("%lf", &p[i][j]);
}
} //memset(dp, -1, sizeof(dp));//不能使用
for (i = ; i <= n; ++i) {
for (j = ; j < n2; ++j) {
dp[i][j] = -;
}
} for (i = ; i < n2 - ; ++i) {
printf("%.3lf ", dfs(n, i));
}
printf("%.3lf\n", dfs(n, n2 - ));
}
return ;
}

1023: Pong’s Birds(概率)的更多相关文章

  1. Deep Reinforcement Learning: Pong from Pixels

    这是一篇迟来很久的关于增强学习(Reinforcement Learning, RL)博文.增强学习最近非常火!你一定有所了解,现在的计算机能不但能够被全自动地训练去玩儿ATARI(译注:一种游戏机) ...

  2. [bzoj2152][聪聪和可可] (点分治+概率)

    Description 聪聪和可可是兄弟俩,他们俩经常为了一些琐事打起来,例如家中只剩下最后一根冰棍而两人都想吃.两个人都想玩儿电脑(可是他们家只有一台电脑)……遇到这种问题,一般情况下石头剪刀布就好 ...

  3. sqlserver中根据表中的配置概率取到数据

      create proc pr_zhanglei_test1 /*功能描述: 根据t_zhanglei_test1中perc设置的概率,取到相应数据old_id */ as declare @per ...

  4. 【BZOJ-3143】游走 高斯消元 + 概率期望

    3143: [Hnoi2013]游走 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2264  Solved: 987[Submit][Status] ...

  5. 【BZOJ-3270】博物馆 高斯消元 + 概率期望

    3270: 博物馆 Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 292  Solved: 158[Submit][Status][Discuss] ...

  6. UVA1637Double Patience(概率 + 记忆化搜索)

    训练指南P327 题意:36张牌分成9堆, 每堆4张牌.每次拿走某两堆顶部的牌,但需要点数相同.如果出现多种拿法则等概率的随机拿. 如果最后拿完所有的牌则游戏成功,求成功的概率. 开个9维数组表示每一 ...

  7. caffe机器学习自带图片分类器classify.py实现输出预测结果的概率及caffe的web_demo例子运行实例

    caffe机器学习环境搭建及python接口编译参见我的上一篇博客:机器学习caffe环境搭建--redhat7.1和caffe的python接口编译 1.运行caffe图片分类器python接口 还 ...

  8. 【BZOJ1415】 [Noi2005]聪聪和可可 概率与期望

    其实题不难,不知提交了几次...不能代码MD...注意一些基本问题...SB概率题 #include <iostream> #include <cstdio> #include ...

  9. 【BZOJ3036】绿豆蛙的归宿 概率与期望

    最水的概率期望,推荐算法合集之<浅析竞赛中一类数学期望问题的解决方法> #include <iostream> #include <cstdio> using na ...

随机推荐

  1. linux安装以及相关配置

    计算机操作系统简介 操作系统是什么 操作系统的内核是什么 两种操作系统用户界面 安装Linux操作系统的准备工作 LINUX发行版(CENTOS.RHEL.FEDORA.UBUNTU.SUSE) RH ...

  2. C# DataTable Column DataType 对应 数据库

      public DataTable MakeDataTable(){ DataTable myTable; DataRow myNewRow; // Create a new DataTable. ...

  3. Django:学习笔记(8)——视图

    Django:学习笔记(8)——视图

  4. vue生命周期探究(二)

    vue生命周期探究(二) 转载自:https://segmentfault.com/a/1190000008923105 上一章我们介绍了vue的组件生命周期和路由勾子,这一章,让我们来看看在vue- ...

  5. BZOJ 1316: 树上的询问

    挺裸的点分治 刚开始想用map水过去,然后做p次点分治,然后T到自闭 最后发现可以sort一遍,然后去重,记录每个数出现的次数,这样就可以双指针,不会漏掉了 #include <bits/std ...

  6. Netty资料

    netty 资料  转自   http://calvin1978.blogcn.com/articles/netty-info.html Netty资料皆阵列在前 Posted on 2016-08- ...

  7. RedisTemplate访问Redis数据结构

    https://www.jianshu.com/p/7bf5dc61ca06 Redis 数据结构简介 Redis 可以存储键与5种不同数据结构类型之间的映射,这5种数据结构类型分别为String(字 ...

  8. 多媒体文件格式分析 MP3文件结构及编解码流程

    多媒体文件格式分析 http://blog.csdn.net/taniya001/article/details/7962864 多媒体文件格式分析 MP3文件结构及编解码流程 http://www. ...

  9. 关于Android RenderScript 的详细说明和一些实用文档

    http://www.cnblogs.com/TerryBlog/archive/2012/03/02/2377251.html RenderScript 是一种低级的高性能编程语言,用于3D渲染和处 ...

  10. 关于Log4Net的使用和配置

    1. 添加log4net.dll引用 2.在添加引用的那层的 AssemblyInfo.cs         注册   : [assembly: log4net.Config.XmlConfigura ...