poj 3071 Football
生活随笔
收集整理的這篇文章主要介紹了
poj 3071 Football
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
http://poj.org/problem?id=3071
?
2^n 支足球隊(duì)比賽,共比n場(chǎng),第一場(chǎng)1號(hào)與2號(hào)比,3號(hào)與4號(hào)比……
每場(chǎng)勝出者進(jìn)入下一場(chǎng),輸者淘汰
每一場(chǎng)都是相鄰的兩個(gè)隊(duì)伍比拼
已知任意兩個(gè)隊(duì)伍比拼獲勝的概率
求最后哪只隊(duì)伍獲勝的概率最大
?
dp[i][j] 到第i場(chǎng)比賽j獲勝的概率
枚舉本場(chǎng)j和k比,dp[i][j]= Σ dp[i-1][j]*dp[i-1][k]*p[j][k]
?
#include<cstdio>using namespace std;const int N=7; const int M=(1<<N)+1;double dp[N+1][M+1],p[M+1][M+1];int main() {int n,m,t,h,ans;while(scanf("%d",&n)!=EOF){if(n==-1) return 0;m=1<<n;for(int i=0;i<m;++i) for(int j=0;j<m;++j)scanf("%lf",&p[i][j]);for(int i=0;i<m;++i) dp[0][i]=1;for(int i=1;i<=n;++i)for(int j=0;j<m;++j){t=j/(1<<i-1);t^=1;dp[i][j]=0;h=t*(1<<i-1)+(1<<i-1);for(int k=t*(1<<i-1);k<h;++k) dp[i][j]+=dp[i-1][j]*dp[i-1][k]*p[j][k];}ans=0;for(int i=0;i<m;++i) ans=dp[n][i]>dp[n][ans] ? i : ans;printf("%d\n",ans+1);}return 0; }?
轉(zhuǎn)載于:https://www.cnblogs.com/TheRoadToTheGold/p/8598886.html
總結(jié)
以上是生活随笔為你收集整理的poj 3071 Football的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Document-对象属性和常用的对象方
- 下一篇: arXiv网站