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. centos7 vim显示行号

    CentOS7下可能有n个账户,让vim显示行号有两种方法:仅让当前用户显示行号和让所有用户显示行号   一.仅让当前用户显示行号 输入命令:vim ~/.vimrc 写入:set nu 保存:wq ...

  2. Java 写文件实现换行

    第一种: 写入的内容中利用\r\n进行换行 File file = new File("D:/text"); try { if(!file.exists()) file.creat ...

  3. 【转】阿里巴巴技术专家杨晓明:基于Hadoop技术进行地理空间分析

    转自:http://www.csdn.net/article/2015-01-23/2823687-geographic-space-base-Hadoop [编者按]交通领域正产生着海量的车辆位置点 ...

  4. sgu 102 Coprimes 解题报告及测试数据

    102. Coprimes time limit per test: 0.25 sec. memory limit per test: 4096 KB 题解: 求一个1-10000之间的数 N 的互质 ...

  5. 简单说说spring的事务机制,以及是如何管理的?

    事务管理可以帮助我们保证数据的一致性,对应企业的实际应用很重要. Spring的事务机制包括声明式事务和编程式事务. 编程式事务管理:Spring推荐使用TransactionTemplate,实际开 ...

  6. HTML5文件上传前本地预览

    HTML5之FileReader的使用 HTML5定义了FileReader作为文件API的重要成员用于读取文件,根据W3C的定义,FileReader接口提供了读取文件的方法和包含读取结果的事件模型 ...

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

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

  8. 5309 《Java程序设计》第6周学习总结

    教材学习内容总结 输入与输出 InputStream与OutputStream 从应用程序角度来看,如果要将数据从来源取出,可以使用输入串流:如果要将数据写入目的地,可以使用输出串流.在Java中,输 ...

  9. Python3.6 安装、后续终端pip 安装模块命令

    1. 下载安装包 https://www.python.org/ftp/python/3.6.4/python-3.6.4-amd64.exe 2. 安装python3.6 增加环境变量(打钩.红框很 ...

  10. WIN7环境安装informatica 提示 不能创建Domain或者node

    查看infa安装的bat文件install.bat,会发现,它调用的是.\Server\Windows\Disk1\InstData\VM\install.exe.所以,我们在安装执行,右键insta ...