Anniversary party Topic Links:
http://acm.hdu.edu.cn/showproblem.php?pid=1520
Test instructions
There are a bunch of people in the company to party, everyone has a happy value, these people have a number of subordinate relations, and everyone does not want to and his direct boss (that is, father, not including ancestors) at the same time on the parties, to the party on the largest happy value of the combined.
Exercises
By test instructions know the company members can form a tree, set value[x] for the x is the root node of the maximum weight of the subtree, child[x] is the child node of x, from the tree can be seen, Value[x]=max (value[x]+∑value[child[child[ X]]],∑VALUE[CHILD[X]])
Code
#include <stdio.h>
#include <string.h>
const int N=20;
Double dp[1<<n],p[n],x;
int main ()
{
int n;
while (~SCANF ("%d", &n))
{
dp[(1<<n) -1]=0.0;
for (int i=0;i<n;++i)
scanf ("%lf", &p[i]);
for (int j= (1<<n) -2;j>=0;--j)
{
x=0;dp[j]=0.0;
for (int k=0;k<n;++k)
{
if (! ( (1<<k) &j))
dp[j]+=dp[j+ (1<<k)]*p[k],x+=p[k];
}
dp[j]= (dp[j]+1.0)/x;
}
printf ("%.5f\n", dp[0]);
}
}
HDU 1520:anniversary Party Tree DP Foundation