[CF678E] Another Sith Tournament([JZOJ4648] 锦标赛)

来源:互联网 发布:mac 多屏幕切换快捷键 编辑:程序博客网 时间:2024/05/19 13:26

Description

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.

下面是译文

403机房最近决定举行一场锦标赛。锦标赛共有N个人参加,共进行N-1轮。第一轮随机挑选两名选手进行决斗,胜者进入下一轮的比赛,第二轮到第N-1轮再每轮随机挑选1名选手与上一轮胜利的选手决斗,最后只剩一轮选手。第i名选手与第j名选手决斗,第i名选手胜利的概率是a[i][j].
作为一号选手的富榄(%%%)想知道如何安排每轮出场的选手可以使得他获胜的概率最大,并求出这个最大概率。
对于30%的数据,N<=10
对于60%的数据,N<=15
对于100%的数据,N<=18

Solution

额~~~这谁翻译的。。。。。

状压性质显然。

然而顺着状压dp会将一个状态胜败拆成不同状态,最后无法统计答案。

我们考虑倒着状压dp,合并状态

0设为已败,1为仍在场上
f[i][S]表示擂主是i状态是S的概率

枚举i,jj表示i与谁对战。

那么我们倒着转移,显然可以从j胜与i胜两种状态转移过来

那么就显然
f[i][S]=max(f[i][S],f[j][Si]×a[j][i]+f[i][Sj]×a[i][j])
(这里SiSj并不一定是真正的减,只是表示减去状态)

Code

#include<cstdio>#include<cstdlib>#include<cmath>#include<cstring>#include<algorithm>#include<iostream>#define fo(i,a,b) for(i=a;i<=b;i++)#define fod(i,a,b) for(i=a;i>=b;i--)using namespace std;int n,cf[19],sx[300001],bz[300001],num;double f[19][300001],a[19][19]; int main(){    freopen("match.in","r",stdin);    cin>>n;    int i,j,k,p;    cf[0]=1;    fo(i,0,n-1)     {        if (i!=0)cf[i]=cf[i-1]*2;        fo(j,0,n-1) scanf("%lf",&a[i][j]);    }     cf[n]=cf[n-1]*2;     f[0][1]=1;    sx[0]=0;    bz[0]=0;    fo(i,0,num)    {        fo(j,0,n-1)        {            if ((sx[i]&cf[j])==0&&bz[sx[i]+cf[j]]==0)            {                bz[sx[i]+cf[j]]=bz[sx[i]]+1;                sx[++num]=sx[i]+cf[j];            }        }    }    fo(i,2,n)    {        fo(p,2,cf[n]-1)        {            if (bz[p]==i)            fo(j,0,n-1)            {                if ((cf[j]&p)>0)                {                    fo(k,0,n-1)                    {                        if((cf[k]&p)>0&&j!=k)                        {                            f[j][p]=max(f[j][p],f[j][p-cf[k]]*a[j][k]+f[k][p-cf[j]]*a[k][j]);                         }                     }                 }            }        }    }    double ans;    fo(i,0,n-1) ans=max(ans,f[i][cf[n]-1]);    printf("%.7lf",ans);} 
0 0
原创粉丝点击