CUC-SUMMER-11-A

A - Football
POJ-3071

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
2
0.0 0.1 0.2 0.3
0.9 0.0 0.4 0.5
0.8 0.6 0.0 0.6
0.7 0.5 0.4 0.0
-1
Sample Output
2
Hint
In the test case above, teams 1 and 2 and teams 3 and 4 play against each other in the first round; the winners of each match then play to determine the winner of the tournament. The probability that team 2 wins the tournament in this case is:

P(2 wins) = P(2 beats 1)P(3 beats 4)P(2 beats 3) + P(2 beats 1)P(4 beats 3)P(2 beats 4)
= p21p34p23 + p21p43p24
= 0.9 · 0.6 · 0.4 + 0.9 · 0.4 · 0.5 = 0.396.
The next most likely team to win is team 3, with a 0.372 probability of winning the tournament.


題意:已知每?jī)蓚€(gè)隊(duì)伍對(duì)陣的勝率七嫌,求哪只隊(duì)伍最后獲勝幾率最高蔑穴,輸出這個(gè)概率

解法:概率DP蝶怔,dp[k][i]表示第k輪第i支隊(duì)伍的勝率幔嫂,則dp[k][i]=dp[k-1][i]dp[k-1][j]a[i][j]鸣哀,其中j是所有在此輪i要擊敗的隊(duì)伍

代碼:

#include<iostream>
#include<cstdio>
using namespace std;
double a[150][150];
double dp[10][150];
int main()
{
    int n;
    while(scanf("%d",&n)&&n!=-1){
        for(int i=1;i<=(1<<n);i++)
            for(int j=1;j<=(1<<n);j++)
                scanf("%lf",&a[i][j]);
        for(int i=1;i<=(1<<n);i++)
            dp[0][i]=1.0;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=(1<<n);j++){
                dp[i][j]=0;
                for(int k=1;k<=(1<<n);k++)
                    if(((k-1)/(1<<i)==(j-1)/(1<<i))&&((k-1)/(1<<(i-1))!=(j-1)/(1<<(i-1))))
                        dp[i][j]+=dp[i-1][j]*dp[i-1][k]*a[j][k];
            }
        }
        int ans=1;
        for(int i=2;i<=(1<<n);i++)
            if(dp[n][i]>dp[n][ans])
                ans=i;
        printf("%d\n",ans);
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市混聊,隨后出現(xiàn)的幾起案子季率,更是在濱河造成了極大的恐慌,老刑警劉巖躲庄,帶你破解...
    沈念sama閱讀 216,997評(píng)論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件查剖,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡噪窘,警方通過查閱死者的電腦和手機(jī)笋庄,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,603評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人直砂,你說我怎么就攤上這事菌仁。” “怎么了静暂?”我有些...
    開封第一講書人閱讀 163,359評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵济丘,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我洽蛀,道長(zhǎng)闪盔,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,309評(píng)論 1 292
  • 正文 為了忘掉前任辱士,我火速辦了婚禮,結(jié)果婚禮上听绳,老公的妹妹穿的比我還像新娘颂碘。我一直安慰自己,他們只是感情好椅挣,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,346評(píng)論 6 390
  • 文/花漫 我一把揭開白布头岔。 她就那樣靜靜地躺著,像睡著了一般鼠证。 火紅的嫁衣襯著肌膚如雪峡竣。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,258評(píng)論 1 300
  • 那天量九,我揣著相機(jī)與錄音适掰,去河邊找鬼。 笑死荠列,一個(gè)胖子當(dāng)著我的面吹牛类浪,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播肌似,決...
    沈念sama閱讀 40,122評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼费就,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了川队?” 一聲冷哼從身側(cè)響起力细,我...
    開封第一講書人閱讀 38,970評(píng)論 0 275
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎固额,沒想到半個(gè)月后眠蚂,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,403評(píng)論 1 313
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡对雪,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,596評(píng)論 3 334
  • 正文 我和宋清朗相戀三年河狐,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,769評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡馋艺,死狀恐怖栅干,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情捐祠,我是刑警寧澤碱鳞,帶...
    沈念sama閱讀 35,464評(píng)論 5 344
  • 正文 年R本政府宣布,位于F島的核電站踱蛀,受9級(jí)特大地震影響窿给,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜率拒,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,075評(píng)論 3 327
  • 文/蒙蒙 一崩泡、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧猬膨,春花似錦角撞、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,705評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至沛申,卻和暖如春劣领,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背铁材。 一陣腳步聲響...
    開封第一講書人閱讀 32,848評(píng)論 1 269
  • 我被黑心中介騙來泰國(guó)打工尖淘, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人著觉。 一個(gè)月前我還...
    沈念sama閱讀 47,831評(píng)論 2 370
  • 正文 我出身青樓德澈,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親固惯。 傳聞我的和親對(duì)象是個(gè)殘疾皇子梆造,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,678評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容