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. quick-cocos2d-x + Lua 开发

    quick-cocos2d-x + Lua 开发      quick-cocos2d-x + Lua 开发 首页在Eclipse中搭建quick-cocos2d-x的lua开发环境. 1. 首先需要 ...

  2. HTTP服务器(3)

    功能完整的HTTP服务器 导语 这个一个功能完备的HTTP服务器.它可以提供一个完整的文档输,包括图像,applet,HTML文件,文本文件.它与SingleFileHttpServer非常相似,只不 ...

  3. 前端学习笔记之BOM和DOM

    前言 到目前为止,我们已经学过了JavaScript的一些简单的语法.但是这些简单的语法,并没有和浏览器有任何交互. 也就是我们还不能制作一些我们经常看到的网页的一些交互,我们需要继续学习BOM和DO ...

  4. Apache 部署HTTPS

    Apache 部署HTTPS 系统:Linux Centos 7.4 x64 应用:Apache 2.4.6 需要安装:mod_ssl 注:确认开启 Include conf/extra/httpd- ...

  5. DNS ARP地址解析原理

    ARP是地址解析协议 主机A与主机B之间如果要进行数据间的传输,需要获取对方的IP与物理地址(MAC),在只清楚ip的情况下,主机A向主机B请求链接,会先查找ARP高速缓存表,是否存在对应的主机B的i ...

  6. 优雅的处理你的Java异常

    本文介绍 本文仅按照业务系统开发角度描述异常的一些处理看法.不涉及java的异常基础知识,可以自行查阅 <Java核心技术 卷I> 和 <java编程思想> 可以得到更多的基础 ...

  7. linux ftp 简单搭建

    1.安装 yum install vsftpd 2.重启服务 /sbin/service vsftpd restartShutting down vsftpd: [ OK ]Starting vsft ...

  8. windows上面非常好用的辅助软件

    1.everything  快速查找本地文件 下载地址:http://www.voidtools.com/

  9. 20145324 《Java程序设计》第3周学习总结

    20145324 <Java程序设计>第3周学习总结 教材学习内容总结 第四章 1.要产生对象必须先定义类,类是对象的设计图,对象是类的实例,建立实例要用new 2.参数名称与对象数据成员 ...

  10. Ansible Playbooks 常用模块

    官网链接:https://docs.ansible.com/ansible/latest/modules/list_of_all_modules.html ansible python module ...