Another Sith Tournament

来源:互联网 发布:淘宝网户外服装男 编辑:程序博客网 时间:2024/05/30 05:41
链接:http://acm.hust.edu.cn/vjudge/problem/401746/origin

题目:

The rules of Sith Tournament are well known to everyone. n Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who will fight in the first battle. As one of them loses, his place is taken by the next randomly chosen Sith who didn't fight before. Does it need to be said that each battle in the Sith Tournament ends with a death of one of opponents? The Tournament ends when the only Sith remains alive.

Jedi Ivan accidentally appeared in the list of the participants in the Sith Tournament. However, his skills in the Light Side of the Force are so strong so he can influence the choice of participants either who start the Tournament or who take the loser's place after each battle. Of course, he won't miss his chance to take advantage of it. Help him to calculate the probability of his victory.



题意:有这么几个人打拳击比赛,规则是按顺序出场,胜者留下,最后留下的为冠军,某个人可以控制出场顺序,知道所有人面对所有人的胜率,问他的最大胜率是多少。

分析:只是一道状态压缩的概率dp,首先不超过18个人,那么可以用18位来枚举出所有已经上场的人的状况,那么dp[1<<20][20]第一维代表上场过的人,第二维表示某个人是目前胜利者的概率,之后某个人的在某些人当中胜出的最大概率就是:他最后上场,与之前的胜者较量胜利的概率,以及他先上场,胜利到最后,在与当中缺失那位战斗胜利的概率的最大值。这样状态转移公式就有了。问题得以解决。
题解:
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <vector>#include <map>#include <string>#include <cstring>#include <functional>#include <cmath>#include <cctype>#include <cfloat>#include <climits>#include <complex>#include <deque>#include <list>#include <set>#include <utility>using namespace std;int n;double s[20][20];double dp[1<<20][20];int main(){//freopen("in.txt","r",stdin);while(~scanf("%d",&n)){memset(dp,0.0,sizeof(dp));for(int p=1;p<=n;p++)for(int q=1;q<=n;q++)cin>>s[p][q];dp[1][1]=1;for(int i=1;i<(1<<n);i++)for(int j=1;j<=n;j++)if((1<<(j-1)|i)==i)for(int k=1;k<=n;k++)//if(j!=k&&(1<<(k-1)|i)==i)//dp[i][j]=(dp[i][j]>dp[i-(1<<(j-1))][k]*s[k][j]+dp[i-(1<<(k-1))][j]*s[j][k])?(dp[i][j]):(dp[i-(1<<(j-1))][k]*s[k][j]+dp[i-(1<<(k-1))][j]*s[j][k]);double ans=0;for(int t=0;t<=n;t++)ans=(ans>dp[(1<<n)-1][t])?ans:dp[(1<<n)-1][t];printf("%.15lf\n",ans);}return 0;}

0 0
原创粉丝点击