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 ...
随机推荐
- HBase的JavaAPI操作
如果是DDL的操作就找HbaseAdmin. 如果是表上的增删改查的操作就找HTable. 附录代码: mport java.util.Arrays; import org.apache.hadoop ...
- 【暴力,STL,水】UVa 1523 - Helicopter
Since ancient time, people have been dreaming of flying in the sky. Eventually, the dream was realiz ...
- hide(1000)跟show(1000)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- NVelocity 实现简单的留言板
留言版简单实现 -------------------------------------------------------------------------------------------- ...
- C++函数学习笔记
C++继承了C语言的全部语法,也包括函数的定义和使用方法. 调用其他函数的函数因为位高权重被尊称为主调函数,被其他函数调用的函数称为被调函数. 函数的返回值由return语句给出,return 表达式 ...
- Git CMD - fetch: Download objects and refs from another repository
命令格式 git fetch [<options>] [<repository> [<refspec>…]] git fetch [<options> ...
- sqlserver 大文件脚本执行
sqlserver2008中需要执行大文件的脚本,查询分析器中打不开,需要用到sql命令,开始使用osql命令,不过提示对应sqlserver2008中的驱动找不到(具体原因未分析-空闲时在处理),使 ...
- JavaScript、jQuery、HTML5、Node.js实例大全-读书笔记2
技术很多,例子很多,只好慢慢学,慢慢实践!!现在学的这本书是[JavaScript实战----JavaScript.jQuery.HTML5.Node.js实例大全] JavaScript.jQuer ...
- NOIP201101&&05
NOIP200701奖学金 难度级别:A: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 某小学最近得到了一笔赞助 ...
- .Net Core 中的包、元包与框架(Packages, Metapackages and Frameworks)
包,元包与框架 本文翻译自 Packages, Metapackages and Frameworks. .Net Core 是一种由 NuGet 包组成的平台.一些产品体验受益于代码包的细粒度定义, ...