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. python字符串搜索

    python字符串字串查找 find和index方法 更多0 python 字符串 python 字符串查找有4个方法,1 find,2 index方法,3 rfind方法,4 rindex方法. 1 ...

  2. TWebBrowser: Determine when a page with Frames is completed

    TWebBrowser: Determine when a page with Frames is completed 6 comments. Current rating: (3 votes). L ...

  3. java中全面的单例模式多种实现方式总结

    单例模式的思想 想整理一些 java 并发相关的知识,不知道从哪开始,想起了单例模式中要考虑的线程安全,就从单例模式开始吧. 以前写过单例模式,这里再重新汇总补充整理一下,单例模式的多种实现. 单例模 ...

  4. hdu6162 Ch’s gift

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6162 题目: Ch’s gift Time Limit: 6000/3000 MS (Java ...

  5. Linux下编程学习一

    本篇主要记录一些在学习LINUX下编程时,, C和C++语言的一些基础的常识, 一. 函数指针 void MyFun(int x); 函数声明 void (*FunP)(int ); 函数指针声明 下 ...

  6. C++切割字符串

    std::string text = "2001_1;2005_5;"; std::stringstream ss(text); std::string sub_str; std: ...

  7. STM32 HAL库详解 及 手动移植

    源: STM32 HAL库详解 及 手动移植

  8. XML常用标签的介绍

    1.引言 在使用Java时经常遇到使用XML的情况,而因为对XML不太了解,经常配置时粘贴复制,现在对它进行总结,以备以后使用. 2.XML常见的定义 (1)XML(Extensible Markup ...

  9. KALI LINUX系统初始化配置

    1.Kali Linux安装VirtualBox增强功能 VirtualBox增强功能介绍:物理机与虚拟机之间的文件共享.物理机与虚拟机之间的剪切板共享.虚拟机的direct3D支持,这样虚拟机窗口就 ...

  10. java计算两个日期之间相隔的月份(向下取整)

    最近需求里面有个需要计算两个日期之间相隔的月份,写起来还挺繁琐,需要将各种情况都要考虑到,写了一个作为以后自己的工具吧. //获取哪一天 public static int getDay(Date d ...