Football
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2769   Accepted: 1413

Description

Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, …, 2n. In each round of the tournament, all teams still in the tournament are placed in a list in order of increasing index. Then,
the first team in the list plays the second team, the third team plays the fourth team, etc. The winners of these matches advance to the next round, and the losers are eliminated. After n rounds, only one team remains undefeated; this team is declared
the winner.

Given a matrix P = [pij] such that pij is the probability that team i will beat team j in a match determine which team is most likely to win the tournament.

Input

The input test file will contain multiple test cases. Each test case will begin with a single line containing n (1 ≤ n ≤ 7). The next 2n lines each contain 2n values; here, the jth value
on the ith line represents pij. The matrix P will satisfy the constraints that pij = 1.0 − pji for all i ≠ j, and pii = 0.0 for all i.
The end-of-file is denoted by a single line containing the number −1. Note that each of the matrix entries in this problem is given as a floating-point value. To avoid precision problems, make sure that you use either the double data type instead
of float.

Output

The output file should contain a single line for each test case indicating the number of the team most likely to win. To prevent floating-point precision issues, it is guaranteed that the difference in win probability for the top two teams will be at least
0.01.

Sample Input

  1. 2
  2. 0.0 0.1 0.2 0.3
  3. 0.9 0.0 0.4 0.5
  4. 0.8 0.6 0.0 0.6
  5. 0.7 0.5 0.4 0.0
  6. -1

Sample Output

  1. 2
  1. 简单的概率题:
  1.  
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <vector>
  5. #include <string>
  6. #include <algorithm>
  7. #include <queue>
  8. using namespace std;
  9. const int  maxn = 1 << 8;
  10. double p[maxn][maxn];
  11. int n,all;
  12. double dp[2][maxn];
  13. int main(){
  14.     while(cin >> n&&n!=-1){
  15.         all = (1 << n);
  16.         for(int i = 1; i <= all; i++)
  17.             dp[1][i] = 1;
  18.         for(int i = 1; i <= all; i++)
  19.             for(int j = 1; j <= all; j++)
  20.                 cin >> p[i][j];
  21.         for(int i = 0; i < n; i++){
  22.             int d = 1<<i;
  23.             for(int k = 1; k <= all; k++){
  24.                 dp[0][k] = dp[1][k];
  25.                 dp[1][k] = 0;
  26.             }
  27.             int sta=1,ed=sta+d;
  28.             while(ed <= all){
  29.                 for(int k = sta; k < ed; k++){
  30.                     for(int a = ed; a < ed+d; a++){
  31.                         dp[1][k] += dp[0][k]*dp[0][a]*p[k][a];
  32.                         dp[1][a] += dp[0][a]*dp[0][k]*p[a][k];
  33.                     }
  34.                 }
  35.                 sta += 2*d;
  36.                 ed = sta+d;
  37.             }
  38.         }
  39.         double ans = dp[1][1];
  40.         int idx = 1;
  41.         for(int i = 2; i <= all; i++){
  42.             if(dp[1][i] > ans){
  43.                 ans = dp[1][i];
  44.                 idx = i;
  45.             }
  46.         }
  47.         cout<<idx<<endl;
  48.     }
  49.     return 0;
  50. }
  51.  

POJ3071-Football(概率DP+滚动数组)的更多相关文章

  1. hdu 4576(概率dp+滚动数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4576 思路:由于每次从某一位置到达另一位置的概率为0.5,因此我们用dp[i][j]表示第i次操作落在 ...

  2. Hello 2019 D 素因子贡献法计算期望 + 概率dp + 滚动数组

    https://codeforces.com/contest/1097/problem/D 题意 给你一个n和k,问n经过k次操作之后留下的n的期望,每次操作n随机变成一个n的因数 题解 概率dp计算 ...

  3. HDU - 4576 Robot(概率dp+滚动数组)

    题意:所有的格子围成一个圈,标号为1~n,若从格子1出发,每次指令告知行走的步数,但可能逆时针也可能顺时针走,概率都是1/2,那么问走了m次指令后位于格子l~r(1≤l≤r≤n)的概率. 分析: 1. ...

  4. POJ3071:Football(概率DP)

    Description Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, …, 2 ...

  5. [poj3071]football概率dp

    题意:n支队伍两两进行比赛,求最有可能获得冠军的队伍. 解题关键:概率dp,转移方程:$dp[i][j] +  = dp[i][j]*dp[i][k]*p[j][k]$表示第$i$回合$j$获胜的概率 ...

  6. POJ3071 Football 概率DP 简单

    http://poj.org/problem?id=3071 题意:有2^n个队伍,给出每两个队伍之间的胜率,进行每轮淘汰数为队伍数/2的淘汰赛(每次比赛都是相邻两个队伍进行),问哪只队伍成为冠军概率 ...

  7. HDU 1024 Max Sum Plus Plus --- dp+滚动数组

    HDU 1024 题目大意:给定m和n以及n个数,求n个数的m个连续子系列的最大值,要求子序列不想交. 解题思路:<1>动态规划,定义状态dp[i][j]表示序列前j个数的i段子序列的值, ...

  8. POJ 3666 Making the Grade (DP滚动数组)

    题意:农夫约翰想修一条尽量平缓的路,路的每一段海拔是A[i],修理后是B[i],花费|A[i] – B[i]|,求最小花费.(数据有问题,代码只是单调递增的情况) #include <stdio ...

  9. HDU 5119 Happy Matt Friends (背包DP + 滚动数组)

    题目链接:HDU 5119 Problem Description Matt has N friends. They are playing a game together. Each of Matt ...

随机推荐

  1. Tuxedo入门学习

    中间件介绍: 介于客户机和server之间的夹层,突破了传统的c/s架构,为构建大规模,高性能,分布式c/s应用程序提供了通信,事物,安全,容错等基础服务,屏蔽了底层应用细节,应用程序不必从底层开发, ...

  2. uboot代码1:uboot启动大体流程, stage1 + stage2

    start.S stage 1: reset: set the cpu to svc32 mode disable the watchdog mask all IRQs(INTMSK, INTSUBM ...

  3. 金额的计算BigDecimal类

    金额的计算BigDecimal类 double d = 9.84; double d2 = 1.22; //注意需要使用BigDecimal(String val)构造方法 BigDecimal bi ...

  4. javascript iframe 视频解码

    function confirmVdo(){ var videoVal = $(".video_src").val(); if(videoVal){ videoVal = vide ...

  5. MPMoviePlayerController导致statusBar消失,导致内存泄露leak

    1.MPMoviePlayerController使statusBar消失 同事写项目时,运行程序总导致statusBar状态条消失,然后就是界面会上移20个像素,导致最下面空白界面,找原因一直不知道 ...

  6. Android开发之大位图二次採样压缩处理(源码分享)

    图片有各种形状和大小.在很多情况下这些图片是远远大于我们的用户界面(UI)且占领着极大的内存空间,假设我们不正确位图进行压缩处理,我们的程序会发生内存泄露的错误. MainActivity的代码 pa ...

  7. Javascript 生成指定范围数值随机数

    JavaScript对随机数的介绍比较少,所以今天分享一下有关随机数的一些事儿.希望能对大家有点小帮助. 主要的公式就是parseInt(Math.random()*(上限-下限+1)+下限); Ma ...

  8. 认识axure部件库中各个部件的属性

    在axure中每一个部件都有自己的属性,下面这个表格,我们就首先来了解认识一下!以下内容来自网站蓝图,版权归原作者所有! 属性名称 属性说明 属性举例 标签 用来标示部件的名称,在axure中,部件名 ...

  9. 基于visual Studio2013解决面试题之0504单链表逆序

     题目

  10. linux中段错误的处理

    在 Linux环境下做C语言项目,由于是在一个原有项目基础之上进行二次开发,而且项目工程庞大复杂,出现了不少问题,其中遇到最多.花费时间最长的问题就是著名的“段错误”(Segmentation Fau ...