石油大 2017年省赛前最后一水 1023: Pong’s Birds
来源:互联网 发布:经典文案 知乎 编辑:程序博客网 时间:2024/05/18 19:43
1023: Pong’s Birds
时间限制: 1 Sec 内存限制: 128 MB提交: 137 解决: 33
[提交][状态][讨论版]
题目描述
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.
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 , 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.
Make sure to output a space character after each number, to prevent the Presentation Error.
样例输入
110 0.50.5 0
样例输出
0.500 0.500
分析:经典的dp题目;思路见代码;
代码:
#include<stdio.h>#include<math.h>double map[200][200];double dp[200][200];int main(){ int T,n; scanf("%d",&T); while(T--) { scanf("%d",&n); int maxn=pow(2,n); for(int i=1;i<=maxn;i++) { for(int j=1;j<=maxn;j++) scanf("%lf",&map[i][j]); } for(int i=1;i<=maxn;i++) dp[0][i]=1.0; int cnt; for(int i=1;i<=n;i++) //一共有n轮比赛 { for(int j=1;j<=maxn;j++) //求出每个人在第i轮比赛的取得胜利的概率,最后状态转移到总冠军 { dp[i][j]=0.0; int tem=j; if(i>1) tem=ceil((double)(j)/(double)pow(2,i-1)); cnt=0; if(tem%2==1) { tem++; //tem和k计算出pow(2,i-1)个对手所在区间的起始位置 for(int k=tem*pow(2,i-1);cnt<pow(2,i-1);cnt++,k--) //pow(2,i-1)控制本轮可能遇到的对手的个数 dp[i][j] += dp[i-1][j]*map[j][k]*dp[i-1][k]; //晋级的概率*获胜的概率*对手晋级的概率 } else { tem--; for(int k=tem*pow(2,i-1);cnt<pow(2,i-1);cnt++,k--) dp[i][j] += dp[i-1][j]*map[j][k]*dp[i-1][k]; } } } printf("%.3f",dp[n][1]); for(int id=2;id<=maxn;id++) printf(" %.3f",dp[n][id]); putchar('\n'); } return 0;}
0 0
- 石油大 2017年省赛前最后一水 1023: Pong’s Birds
- 中石油多校联赛(最后一水) Pong’s Birds(dp)
- 石油大OJ 1023 问题 L: Pong’s Birds【概率Dp】
- 2017年省赛前最后一水---K题
- 2017年省赛前最后一水---C题
- 2017年省赛前最后一水---A题
- 2017年省赛前最后一水---B题
- 2017年省赛前最后一水 Problem A: String
- 2017年省赛前最后一水 Problem I: ACM’s OCR II(只有你想不到!!!)
- 2017年省赛前最后一水 Problem C: a*b%c
- Pong’s Birds(概率 模拟)
- 校赛前一水
- 石油大 oj2707
- 南阳省赛前拉力赛成长记录(一)
- 谷歌2007年上交大考试最后一题解答
- 中石油 Teacher’s Day
- 左宗棠:大清朝最后一棵顶梁柱
- 2017、5、13日省赛前组队训练赛。
- 正向代理和反向代理浅谈
- 无法发送电子邮件,可能原因:您的主机禁用了mail()函数
- ACdream 1001 整数交换
- Nginx+Tomcat搭建集群
- C语言实现电子投票管理系统
- 石油大 2017年省赛前最后一水 1023: Pong’s Birds
- Ftp 链接服务器 多次失败
- 迷宫问题(dfs)POJ
- Android快速开发系列 10个常用工具类
- 常用排序算法之希尔排序
- leetcode83Remove Duplicates from Sorted List
- MySQL(2)-约束的添加及删除
- 计算机网络基础——网络的性能
- 怎么判断IOS安装包中是否包含jspatch代码