NEED HELP IN ( ANOTHER SITH TOURNAMENT 678E ) codeforces

Revision en1, by javacoder1, 2016-07-12 22:54:07
I was looking through this accepted code and seems that the states of dp are dp[i][j] meaning that the submask i is considered and j is the winner.I am confused about two things.
1. dp[i][j] shouldn't be max(dp[i][j],p[j][k]*dp[i^(1<<k)][j] + p[j][k]*dp[i^(1<<j)][k])
 meaning j is the winner of the mask so j was winner of mask excluding k and defeated k. and k was the winner of mask excluding j and j defeated k.
2. we want 0 to be winner so why we are iterating to get final answer.shouldn't it be dp[(1<<N)][0] 
#include <iostream>
#include <iomanip>
using namespace std;

double p[18][18];
double dp[1<<18][18];

int main()
{
	int N;
	cin >> N;
	for(int i=0;i<N;i++) for(int j=0;j<N;j++) cin >> p[i][j];
	for(int i=0;i<N;i++) dp[1][i] = 0.0;
	dp[1][0] = 1.0;
	for(int i=2;i<(1<<N);i++) for(int j=0;j<N;j++) if(i&(1<<j))
	{
		dp[i][j] = 0.0;
		for(int k=0;k<N;k++) if((i&(1<<k))&&(k!=j))
		{
			dp[i][j] = max(dp[i][j],p[j][k]*dp[i^(1<<k)][j] + p[k][j]*dp[i^(1<<j)][k]);
		}
	}
	double best = 0;
	for(int i=0;i<N;i++) best = max(best,dp[(1<<N)-1][i]);
	cout  << setprecision(20) << best << '\n';
}

THe editorial as well as all solution seems to do the same thing.Can someone explain?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English javacoder1 2016-07-12 22:54:07 1350 Initial revision (published)