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. 001-搭建spring boot项目

    1.第一步.file--new--project. 2.spring initializr--project sdk--default--next 3. 4.spring boot--选择依赖项--n ...

  2. IOS开发如何入门

    说到 iOS 开发,自己学得也很浅.不过至少独立一人完成了一个应用的开发到项目上线整个过程.分享一下自己的建议和想法. 首先建议阅读 Start Developing iOS Apps Today,你 ...

  3. [转]Unix/Linux开源世界资源链接汇总

    转自:http://blog.csdn.net/21aspnet/article/details/6754126 最后更新:2012.12.04 说明:好东西在后面,Linux镜像基本涵盖全球主要下载 ...

  4. Eclipse 导入Maven 项目报错

    新建Maven项目时出错:org.apache.maven.archiver.MavenArchiver.getManifest   新建Maven项目时出错:org.apache.maven.arc ...

  5. hive报错汇总

    1.需要注意的是,要在namenode(超级用户)上操作,貌似是 hive> insert into table record_partition partition(trancation_da ...

  6. NIO 02 (转)

    本文转自:http://weixiaolu.iteye.com/blog/1479656 SelectionKey.OP_ACCEPT // 服务端监听,并注册OP_ACCEPT事件后,就已准备好接受 ...

  7. Java实现:服务端登录系统并跳转到系统内的指定页面(不调用浏览器)

    Java实现:服务端登录系统并跳转到系统内的指定页面(不调用浏览器) 1,思路:根据爬虫思想: 2,代码: /** * ClassName:AuthFr * Function: TODO * Reas ...

  8. MVC的局部视图传参的小技巧--见人才网头部导航

    当我们设计一个局部视图时,当出现有类似导航的功能(如:选择左边的某个按钮跳到某个页,且顶部导航也作相印改变),如果我们选择把导航作为局部视图来处理,调用就可以做如下处理: @Html.RenderAc ...

  9. 20145314郑凯杰《信息安全系统设计基础》第5周学习总结 part B

    20145314郑凯杰<信息安全系统设计基础>第5周学习总结 part B 在前四天的学习中,我主要对课本知识进行了总结,在本周后三天的学习过程中,我进行实践并截图. http://www ...

  10. webservice的cxf的客户端

    1.新建一个java项目 2.用cmd命令生成客户端的使用说明文档 wsdl2java -p xiaostudy -d . http://127.0.0.1:9998/number?wsdl 3.导入 ...