给定2^n 支足球队进行比赛,n<=7. 队伍两两之间有一个获胜的概率,求每一个队伍赢得最后比赛的概率是多少?

状态其实都是很显然的,一开始觉得这个问题很难啊,不会。dp[i][j] 表示第i支队伍赢得前j轮比赛的概率。(这个题目处理区间的时候比较恶心,小心点即可)。

   1:   
   2:  #include <iostream>
   3:  #include <cstdio>
   4:  #include <cstring>
   5:  #include <map>
   6:  #include <algorithm>
   7:  using namespace std;
   8:   
   9:  double p[135][135];
  10:  double dp[135][10];
  11:   
  12:  pair<int,int> range(int idx, int round)
  13:  {
  14:      int x = (idx>>round) ^1;
  15:      return make_pair(x<<round, (x<<round) + (1<<(round)) - 1);
  16:  }
  17:  int main()
  18:  {
  19:  //    freopen("1.txt","r",stdin);
  20:      int n;
  21:      while(cin>>n && n !=-1)
  22:      {
  23:          for(int i=0; i<(1<<n); i++)
  24:          {
  25:              for(int j=0; j<(1<<n); j++)
  26:              {
  27:                  cin>>p[i][j];
  28:              }
  29:          }
  30:          memset(dp,0,sizeof(dp));
  31:          for(int i=0; i< (1<<n); i++)
  32:          {
  33:              dp[i][0] = p[i][i^1];
  34:          }
  35:          for(int round=1; round<n; round++) // round
  36:          {
  37:              for(int j=0; j< (1<<n); j++)
  38:              {
  39:                  pair<int,int> r = range(j, round);
  40:                  for(int k = r.first; k<= r.second; k++)
  41:                  {
  42:                      dp[j][round] += p[j][k] *dp[k][round - 1]*dp[j][round-1];
  43:                  }
  44:              }
  45:          }
  46:          int idx  = -1;
  47:          double ret = 0;
  48:          double sum = 0;
  49:          for(int i=0; i<(1<<n); i++)
  50:          {
  51:              sum+= dp[i][n-1];
  52:              if(dp[i][n-1] > ret)
  53:              {
  54:                  idx = i;
  55:                  ret = dp[i][n-1];
  56:              }
  57:          }
  58:          cout<<idx+1<<endl;
  59:      }
  60:  }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

POJ 3701 概率DP的更多相关文章

  1. POJ 2096 (概率DP)

    题目链接: http://poj.org/problem?id=2096 题目大意:n种bug,s个子系统.每天随机找一个bug,种类随机,来自系统随机.问找齐n种bug,且每个子系统至少有一个bug ...

  2. POJ 2151 概率DP

    主要的子问题是每一个队伍有一个做出题目的概率,求做出k个题目的概率.简单的简单的组合数DP.想清楚即可. 1: #include <iostream> 2: #include <cs ...

  3. Scout YYF I POJ - 3744(概率dp + 矩阵快速幂)

    题意: 一条路上有n个地雷,你从1开始走,单位时间内有p的概率走一步,1-p的概率走两步,问安全通过这条路的概率 解析: 很容易想到 dp[i] = p * dp[i-1] + (1 - p) * d ...

  4. poj 3071 概率dp

    转自:cxlove 题目:有2^n个队,相邻的两两打淘汰赛,,求最后哪个队夺冠的概率最大 dp[i][j]表示第i轮的时候,第j去支队伍赢的概率. 那么dp[i][j]的前提就是i-1轮的时候,j是赢 ...

  5. poj 3744 概率dp+矩阵快速幂

    题意:在一条布满地雷的路上,你现在的起点在1处.在N个点处布有地雷,1<=N<=10.地雷点的坐标范围:[1,100000000]. 每次前进p的概率前进一步,1-p的概率前进1-p步.问 ...

  6. Check the difficulty of problems - poj 2151 (概率+DP)

    有 T(1<T<=1000) 支队伍和 M(0<M<=30) 个题目,已知每支队伍 i 解决每道题目 j 的的概率 p[i][j],现在问:每支队伍至少解决一道题,且解题最多的 ...

  7. poj 2151 概率DP(水)

    Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5750   ...

  8. poj - 2096 概率dp (找bug)

    题意:一个人一天只能找1个bug ,这个bug属于s个子系统中的某一个子系统,属于n种bug 中的某一种 ,求 这个人找出n种bug ,并且s个系统都bug的期望 (每个系统的一定可以找出bug) 一 ...

  9. poj 3744 概率dp 快速幂 注意排序 难度:2

    /* Scout YYF I Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5304   Accepted: 1455 De ...

随机推荐

  1. ARM Linux bootloader笔记

    .text //指定了后续编译出来的内容放在代码段[可执行] .global //告诉编译器后续跟的是一个全局可见的名字[可能是变量,也可以是函数名] _start /*函数的其实地址,也是编译.链接 ...

  2. [改善Java代码]子列表只是原列表的一个视图

    List接口提供了subList方法,其作用是返回一个列表的子列表.这与String类的subString有点类似.但是他们的功能是否相同?看代码: import java.util.ArrayLis ...

  3. hdu1560 搜索

    从原串的最大长度开始枚举,当某个长度的值能保存所有串时,即成功.对每个长度进行深搜,每次取某个串的第一个. #include<iostream> #include<cstdio> ...

  4. JavaScript部分总结

    一.词法结构 1.js里面区分大小写 2.注释分为两类:  // 单行注释    /*多行注释*/ 3.字面量(直接量 literal) 12                             ...

  5. tomcat 安装

    升级系统之后很长一段时间没有用tomcat(主要是没做东西),这两天要开始干活了,发现竟然没法发用了....ok,重新整一遍.算是温习. 上次所有环境的搭建基本都是师兄帮我,自己做得东西很少,这次就正 ...

  6. C#数组比较取值

    string strs = string.Empty;            string[] strArray1 = { "a", "b", "c& ...

  7. 百练 2973 Skew数 解题报告

    思路: 计算出每一个skew数的不同位数表示的权值,然后用该位与权值相乘.用int数组来装权值,用char数组来装skew数. 代码: #include<stdio.h> #include ...

  8. DialogFragment

    DialogFragment 从Android 3.0 (API level 11)开始引入,如果想在低于该版本的系统上使用,需用android.support.v4.app.DialogFragme ...

  9. 使用JS调用WebService接口

    <script> $(document).ready(function () { var username = "admin"; var password = &quo ...

  10. 【leetcode】365. Water and Jug Problem

    题目描述: You are given two jugs with capacities x and y litres. There is an infinite amount of water su ...