POJ 3701 概率DP
给定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的更多相关文章
- POJ 2096 (概率DP)
题目链接: http://poj.org/problem?id=2096 题目大意:n种bug,s个子系统.每天随机找一个bug,种类随机,来自系统随机.问找齐n种bug,且每个子系统至少有一个bug ...
- POJ 2151 概率DP
主要的子问题是每一个队伍有一个做出题目的概率,求做出k个题目的概率.简单的简单的组合数DP.想清楚即可. 1: #include <iostream> 2: #include <cs ...
- Scout YYF I POJ - 3744(概率dp + 矩阵快速幂)
题意: 一条路上有n个地雷,你从1开始走,单位时间内有p的概率走一步,1-p的概率走两步,问安全通过这条路的概率 解析: 很容易想到 dp[i] = p * dp[i-1] + (1 - p) * d ...
- poj 3071 概率dp
转自:cxlove 题目:有2^n个队,相邻的两两打淘汰赛,,求最后哪个队夺冠的概率最大 dp[i][j]表示第i轮的时候,第j去支队伍赢的概率. 那么dp[i][j]的前提就是i-1轮的时候,j是赢 ...
- poj 3744 概率dp+矩阵快速幂
题意:在一条布满地雷的路上,你现在的起点在1处.在N个点处布有地雷,1<=N<=10.地雷点的坐标范围:[1,100000000]. 每次前进p的概率前进一步,1-p的概率前进1-p步.问 ...
- Check the difficulty of problems - poj 2151 (概率+DP)
有 T(1<T<=1000) 支队伍和 M(0<M<=30) 个题目,已知每支队伍 i 解决每道题目 j 的的概率 p[i][j],现在问:每支队伍至少解决一道题,且解题最多的 ...
- poj 2151 概率DP(水)
Check the difficulty of problems Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5750 ...
- poj - 2096 概率dp (找bug)
题意:一个人一天只能找1个bug ,这个bug属于s个子系统中的某一个子系统,属于n种bug 中的某一种 ,求 这个人找出n种bug ,并且s个系统都bug的期望 (每个系统的一定可以找出bug) 一 ...
- poj 3744 概率dp 快速幂 注意排序 难度:2
/* Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5304 Accepted: 1455 De ...
随机推荐
- plsql常用快捷键
plsql使用技巧 1.类SQL PLUS窗口:File->New->Command Window,这个类似于oracle的客户端工具sql plus,但比它好用多了. 2.设置关键字自动 ...
- HDU 1016 Prime Ring Problem (DFS)
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- Oracle查询被锁的表及进程的方法
Oracle查询可以有多种方法,下面为您介绍的是如何Oracle查询被锁的表及Oracle查询连接的进程的方法,希望对您能够有所帮助. 一.查看被锁的表 select p.spid,a.serial# ...
- ListView使用自定义适配器的情况下实现适配器的控件点击事件执行Activity界面中的方法
如果ListView使用的是自定义的适配器,比如MyArrayAdapter extends ArrayAdapter<String> 那么,如何实现适配器中的点击事件执行activity ...
- ActiveMQ(5.10.0) - Configuring the Simple Authentication Plug-in
The easiest way to secure the broker is through the use of authentication credentials placed directl ...
- JQuery合并列(可用于导出Word)
在网上找了一些JQuery合并列的例子,但是都是用.hide()的方式,这样导致了在导出Word的时候表格严重变形 自己写了一个用.remove()方式的合并列 function arrangeTab ...
- python - 图例显示中文
# -*- coding: utf-8 -*- """ Created on Mon Nov 30 13:24:00 2015 @author: jx_luo " ...
- %r与%s的区别
%r用rper()方法处理对象 %s用str()方法处理对象 有些情况下,两者处理的结果是一样的,比如说处理int型对象. 例一: print "I am %d years old.&quo ...
- Cocos2d-x优化中关于背景图片优化
由于背景图片长时间在场景中保存,而且图片很多,我们可以对其进行一些优化.我们通过如下几个方面考虑优化:1.不要Alpha通道背景图片的特点是不需要透明的,所以纹理格式可以采用不带有Alpha通道格式, ...
- NSArray的Category
NSArray的Category 前言 项目中自己通过各种渠道及结合项目的经验整理了一套自己的工具包,里面有各种Category,及封装的方法,方便项目使用,今天先分享一下NSarray的Catego ...