Description
The rules of Sith tournament is well known to everyone. N Sith take part in the tournament. The tournament starts with the random choice of both Sith who'll fight in the first battle. As one of them loses, he place is taken by the next randomly chosen Sith who didn ' t fight before. Does it need to being said that all 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 is so strong so he can influence the choice of participants either 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.
Here is the translation
403 Room recently decided to hold a tournament. The tournament has a total of n individuals participating in a total of N-1 rounds. The first round of random selection of two players to duel, the winner into the next round, the second to N-1 round and then randomly pick 1 players each round to duel with the last round of victory, and finally only one round of players left. The first player fights with the first J, and the probability of the first contestant winning is A[i][j].
%%%, a player who wants to know how to arrange each round of appearances, can make him the most likely winner and find the maximum probability.
For 30% of data, n<=10
For 60% of data, n<=15
For 100% of data, n<=18 solution
Amount ~ ~ ~ this who translates ...
The nature of the pressure is obvious.
However, along the pressure DP DP will be a state of victory and defeat into different states, and finally unable to statistical answer.
We consider the inverted pressure DP DP, the combined state
0 0 is set to be defeated, 1 1 is still on the court
Set F[i][s] f[i][s] means that Leizhu is the probability that I I state is S S
Enumeration I,j I,j, J J indicates who I play against.
So we're moving backwards, obviously from J-J wins and I-I-win two states.
Well, obviously,
F[i][s]=max (F[i][s],f[j][s−i]xa[j][i]+f[i][s−j]xa[i][j]) F[i][s]=max (F[i][s],f[j][s-i]\times a[j][i]+f[i][S-j]\ Times A[i][j])
(Here S−i s-i and s−j s-j are not necessarily real minus, just mean minus state) 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); }